Does Java do anything to prevent files from changing out from under it?

Martin Buchholz martinrb at google.com
Tue May 20 13:15:26 UTC 2008


On Tue, May 20, 2008 at 12:24 AM, Florian Weimer <fw at deneb.enyo.de> wrote:
> * Martin Buchholz:
>
>> Fixing this would require hooking into the OS file modification
>> notification mechanism; not easy; how to abort a class load in
>> progress?
>
> Does the JVM ever reopen a JAR file to read more classes?

Hmmm...The jar/zip code keeps the file descriptor from the
first open, then calls read() whenever the data for an entry
needs to be read (e.g. class load is required).

> If it this isn't the case, at least there's a clean way to replace JARs
> on UNIX platforms while a JVM is still referencing them.

Yes, I believe it is true that if you practice proper hygiene when
replacing jars (rm first, then mv) then the running java process
should continue to work fine.  At least, none of the bug reports
about crashes after replacing jars stated, "But....I WAS practicing
proper file descriptor hygiene!"

Martin

Martin



More information about the core-libs-dev mailing list