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

S

Shailender Bathula

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?

Thanks,
Shailender
 
S

Sanjay

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
del.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top