If I add a shutdown hook to my Java program\'s runtime like so:
public class MyShutdownHook implements Runnable
{
@Override
public void run(
Any time the JVM can exit gracefully, the shutdown hook is run. It is not run if:
If the process is killed, a shutdown hook will not be executed.
If the process crashes, a shutdown hook will not be executed.
If you have a Windows service and the shutdown hook takes to long to execute, it will be terminated.
If you pull the plug out the back of your computer then the shut-down hook won't run. Other situations include:
They only run if the process "shuts down normally." If the process is killed forcefully from the OS or if it's crashing due to resource issues (e.g., out of memory), shutdown hooks won't be invoked.
when you do Runtime.getRuntime().halt()
the JVM or when the OS kills the process without allowing it to run any cleanup, also when you have eclipse terminate the program (when running it under eclipse)