Java shutdown function not executed
•
Java
In main () of my application, I have the following code to back up the data so that it will not be lost when the system is shut down
//add hook to trigger Production Shutdown sequence Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { Production.shutdown(); } }));
However, whether I press the stop button in the IDE or rely on log entry (the code shown below), it does not seem to save data to the database or write any logs to the console
ctx.deploy(server); server.start(); //start the production process Production.init(); system.in.read(); server.stop();
Why is this shutdown not performed?
Solution
You need to use the exit button instead of stop, see my answer here for more details
Please note that this feature is currently available only in run mode, not in debugging
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码