Dynamic Class Reloading and Class File Update and Lock/Synchronization?

Discussion in 'Java' started by Shailender Bathula, Feb 16, 2005.

  1. Hi,

    I need to check classes in a file system directory every few seconds to
    see if they have been modified and dynamically reload the modified
    classes at run-time. I am using the URLClassLoader for loading the
    modified classes. I have got the reloading going.

    But, I have a question about what happens when the class files are
    updated using file system commands like cp, mv, rm etc. and how it
    affects the ClassLoader.loadClass method. Let's say a new version of a
    class is getting copied into the classes directory while
    ClassLoader.loadClass for the old version of the class file has not
    finished yet. Where does the synchronization need to happen? Do the
    lower level operating system routines used by the file system commands
    and ClassLoader.loadClass take care of it? Or, do I have to explicitly
    perform synchronization on the classes directory by creating a
    temporary lock file. That is the class file update process and run-time
    class reloading thread check to see if a temporary lock file has been
    created; if not, create one (using atomic File.createNewFile) and start
    updating the class file or reading the class file.

    ClassLoader.loadClass method eventually calls a native method
    findBootstrapClass for loading standard Java classes. I do not know
    much about the lower level operating system routines used by commands
    like cp, mv, rm and findBootstrapClass.

    Can someone explain what happens in the scenario described? Since what
    I am trying to do is similiar to hot deployment or class reloading
    feature of Java Web Containers like Tomcat, WebSphere, do they
    lock/synchronize at some level to make sure the reload does not result
    in an inconsistent scenario?

    Shailender Bathula, Feb 16, 2005
    1. Advertisements

  2. Sanjay

    Sanjay Guest

    My understanding is that O/S locks the file for doing anything on it
    (even for reading), so before mv, cp or anyother operation on the file
    it will check the lock and act accordingly. Hence you would get an
    error while executing mv, cp..

    P.S: Just try to do this simple cross check by writing a program that
    will read the file for 10 minutes, meanwhile try executing the mv or
    Sanjay, Feb 17, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuzzyman
    Andrew MacIntyre
    Dec 5, 2003
  2. Robert Brewer
    Robert Brewer
    Dec 5, 2003
  3. Replies:
    Thomas Hawtin
    Nov 15, 2006
  4. k3xji
    Gabriel Genellina
    Dec 30, 2008
  5. nano2k

    Application.Lock()/UnLock() or lock(Application)

    nano2k, Jul 23, 2007, in forum: ASP .Net Web Services
    Aug 9, 2007

Share This Page