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