Re: Detecting multiple class loaders



Chris wrote:
Is there any way to detect when a class has been loaded by two different class loaders?

Our app has a class that reads and writes a file on disk. The file gets corrupt if more than one process gets at it at once. We can detect multiple processes by locking the file on disk and throwing an error; no problem. We can control access by multiple threads using synchronization. So far, so good.

The problem is Websphere. When this class gets used in a webapp, Websphere, like most other app servers, creates a classloader just for that webapp. But it does more than that; it creates multiple classloaders and they all load the class independently. And we get corruption.

Other than fix Websphere (and we're working on it), is there another way, in general, we can use to ensure that only one classloader within a JVM loads a given class?

Put the class in a place where it will be loaded by the same
classloader for all web apps.

Classloaders always try to delegate to their parent, so if the
class can be loaded by a classloader that is ancestor to all the
relevant classloader it will be loaded by that. And therefore
only exist in one copy.

And no need to "fix" WebSphere, because this is how Java and
app servers are supposed to work.

Arne
.



Relevant Pages

  • Re: Detecting multiple class loaders
    ... The file gets corrupt if more than one process gets at it at once. ... We can detect multiple processes by locking the file on disk and throwing an error; ... When this class gets used in a webapp, Websphere, like most other app servers, creates a classloader just for that webapp. ...
    (comp.lang.java.programmer)
  • Detecting multiple class loaders
    ... We can detect multiple processes by locking the file on disk and throwing an error; ... When this class gets used in a webapp, Websphere, like most other app servers, creates a classloader just for that webapp. ...
    (comp.lang.java.programmer)
  • Re: About classloader
    ... Free Java Certification Mock Exams: ... Free Java and WebSphere Tutorials: ... JVM running on the server. ... and extremely important component known as a classloader. ...
    (comp.lang.java.programmer)
  • Re: Can a java program know what kind of server it is running on?
    ... classloader order is set to PARENT_LAST. ... WebSphere is messing things ... up and being able to detect this case will save major headaches down ... changing ClassLoader invocation order? ...
    (comp.lang.java.help)
  • resourcebundle & jstl
    ... I am running a webapp in websphere 5.1. ... When the app is started, ... resourcebundle is getting loaded properly as I see ...
    (comp.lang.java.programmer)