What happens if I delete the xx.jar file after I started to execute the xx.jar
I have a server program running a java binary code (xx.jar file). While it is running I erroneously delete the xx.jar file. The program continues to run. But I am not sure if the results will be correct, and I am not sure if the program will fail.
When I delete the xx.jar file, the program was in a method for a long time and still it is in that method call. When it calls another method call will, my program fail?
开发者_运维技巧I am asking this question because If deleting the file has no harm I will be gaining about 3-4h on a server machine
There is no guarantee that the JVM will load all classes from a .jar
file into memory, although it may pre-load some or all of the .jar
as an optimization.
If this fails, and I imagine it would at some point, it would not happen during the middle of execution of a method. It would be at a point where a new class must be loaded from the classpath and the JVM can't access that file anymore. Then you would fail with NoClassDefFoundError
or worse.
So, no, I would definitely not advise you to do this, even if it happens to work in some cases.
Depending on your operating system, this will or will not be a problem. On Linux, for example, a file isn't really deleted until all applications that have it opened close it. The file will be gone from the directory listing but it still exists and can be read (and even written!) by any application with a valid file descriptor open.
Whether or not the JVM keeps file descriptors open to all jar files of your application, I don't know. I wouldn't rely on it doing so, even if it does seem to work ok sometimes.
You will come to know when you completely deploy and redeploy an application and restart it .
Dependency functionality will fail and Expection will be thrown
精彩评论