Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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

like image 546
ogzylz Avatar asked Apr 23 '10 07:04

ogzylz


People also ask

Can .jar files be deleted?

You cannot delete a JAR file while any components that reference the file are deployed.

How do I delete an executable JAR file?

To learn more, see Using the Change Center. From the left navigation pane, select JARs from under Resource Browser. The Summary of JARs page is displayed. In the Options field of the JAR you want to delete, click the Delete icon.

What does executable JAR file mean?

A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link.


1 Answers

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.

like image 193
Sean Owen Avatar answered Oct 01 '22 02:10

Sean Owen