tags:

views:

73

answers:

3

I have a server program running a java binary code (xx.jar file) While it is running I erranously 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

+2  A: 

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.

Sean Owen
Currenty program is still running the same method when I deleted the xx.jar file. I put exactly same xx.jar file in to the folder that I deleted xx.jar. Will this solution prevent a failure when the program exits the method running and call another method or class?
ogzylz
My program called a new class Now and did not resulted in error. Thnx a lot
ogzylz
A: 

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.

Gerco Dries
thank god I am using Linux. ------>> another question I asked before -->> Currenty program is still running the same method when I deleted the xx.jar file. I put exactly same xx.jar file in to the folder that I deleted xx.jar. Will this solution prevent a failure when the program exits the method running and call another method or class? – ogzylz 3 secs ago edit [delete this comment]
ogzylz
My program called a new class Now and did not resulted in error. Thnx a lot
ogzylz
A: 

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

harigm
Nope it continued to work fine. But before it calls other class/method I copied another xx.jar deployed same as the deleted xx.jar one.
ogzylz