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?

Are you by any chance using the broken singleton pattern based on a static instance member? If so your only option is to use an external resource to lock on as a workaround. As others have pointed out sockets are among the obvious candidates.

Silvio Bierman
.



Relevant Pages

  • Re: Detecting multiple class loaders
    ... The file gets corrupt if more than one process gets at it at once. ... 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: 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. ... someone else has the socket and is writing. ...
    (comp.lang.java.programmer)
  • Re: Detecting multiple class loaders
    ... Our app has a class that reads and writes a file on disk. ... corrupt if more than one process gets at it at once. ... we can use to ensure that only one classloader within a JVM ... Have the writing code allocate a server socket on a rarely used port. ...
    (comp.lang.java.programmer)
  • Re: 4 CONSECUTIVE CORRUPT DISK DISASTERS WITH WIN2K
    ... Disk and drive controller. ... The application install is responsible for placing the shortcuts. ... unreadable / corrupt. ... Restoration of data files from backup hard drives during re-installation ...
    (microsoft.public.win2000.general)
  • Re: defrag/ error check/ Safe mode problems
    ... You need to find out whether you have a failing hard disk? ... For chkdsk to ... but \FOUND.002 was the "corrupt" file. ... > retried and it went to Safe Mode, but I couldn't get sysclean to run. ...
    (microsoft.public.windowsxp.perform_maintain)