ogzylz ogzylz - 29 days ago 15
Java Question

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

Answer

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.