Re: Detecting multiple class loaders




"Chris" <spam_me_not@xxxxxxxxxx> wrote in message
news:47e12e73$0$29056$9a6e19ea@xxxxxxxxxxxxxxxxxxxxxxx
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?

Have the writing code allocate a server socket on a rarely used port. If
successful, the file write can proceed. Otherwise, someone else has the
socket and is writing. Afer writing, release the socket. Note that the
socket is never actually used. Sockets are a global resource independent of
classloaders and allocation qualifies as atomic test-and-set.

Matt Humphrey http://www.iviz.com/


.



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)
  • 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: Inter-process communication - does data hit disk?
    ... > How big is a socket buffer anyway? ... If your dataset gets substantially larger than physical RAM, ... going to have to wait for the disk sometimes, ... more than a tiny amount of data in the pipe at a time". ...
    (comp.os.linux.development.apps)
  • Re: Inter-process communication - does data hit disk?
    ... > You should probably investigate the socket API further. ... > It certainly will hit disk if you write enough data to require the ... >> the complicated business of sending commands to the hard disk, ... > is going to decide to write some of your data out in order to free RAM ...
    (comp.os.linux.development.apps)
  • Re: Re[2]: sendfile to nonblocking socket
    ... 2G from disk, but not writing them to socket. ... splice(from disk, to pipe) with SPLICE_F_NONBLOCK ... I am not sure splice() to socket is actually implemented with 0-copy ...
    (Linux-Kernel)