What happens if I delete the xx.jar file after I started executing xx.jar

I have a server program using Java binary (xx.jar file) Although it works, I mistakenly delete the xx.jar file. The program continues to work. But I'm not sure if the results will be correct, and I'm not sure if the program will fail?

When I delete the xx.jar file, the program has been in the method for a long time and is still in this method call. When it calls another method call, will my program crash?

I ask this question because if deleting the file is not harmful, I will get about 3-4 hours on the server machine

+4
source share
4 answers

Depending on your operating system, this will or will not be a problem. For example, on Linux, a file is not deleted until all applications opened by it close it. The file will be deleted from the list of directories, but it still exists and can be read (and even written!) By any application with an open file descriptor.

Regardless of whether the JVM supports file descriptors for all the jar files of your application, I do not know. I would not rely on it, even if it really works fine.

+2
source

There is no guarantee that the JVM will load all classes from the .jar file into memory, although it may preload part or all of the .jar as an optimization.

If this fails, and I believe that at some point this will not happen in the middle of the method. This would be at the point where the new class should be loaded from the class path, and the JVM would no longer be able to access this file. Then you fail with NoClassDefFoundError or worse.

So no, I would definitely not advise you to do this, even if this happens in some cases.

+7
source

You will find out when you fully deploy and reinstall the application and restart it.

Dependency functionality will fail and an error will be expended.

0
source

You will get a NullPointerException if your web container is tomcat 7.0.59. I did it minutes ago.

0
source

Source: https://habr.com/ru/post/1307759/


All Articles