Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dynamic Class Reloading and Class File Update and Lock/Synchronization?

Thread Tools

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

Shailender Bathula
Posts: n/a

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?


Reply With Quote
Posts: n/a
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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically compiling and reloading SWIG .pyd file Dave Guthrie Python 0 05-11-2010 09:35 AM
Eclipse+Glassfish & Dynamic Reloading Patrick Java 1 08-28-2008 01:18 AM
noob: reloading modified python file within Python Shell johnny Python 2 09-10-2007 08:11 PM
Saving performance when reloading xml file Bertram Hurtig Java 1 09-07-2007 08:46 PM
class reloading and constants Xavier Noria Ruby 1 11-12-2006 10:40 PM