Java Shutdown not executing

Basically () of my application, I have the following code for backing up data so that it does not get lost in the event of a system shutdown.

//add hook to trigger Production Shutdown sequence Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { Production.shutdown(); } })); 

However, if I click the Stop button in my IDE or rely on logging in (the code shown below), it never saves data in the database or writes any logs to the console.

  ctx.deploy(server); server.start(); //start the production process Production.init(); System.in.read(); server.stop(); 

How does this shutdown function fail?

+6
source share
1 answer

For more details, you need to use the Exit button, not the Stop button, see my answer here .

Please note that this feature is only available in Run mode, and not in Debug.

+11
source

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


All Articles