Java Close Hook
In a Java program, you can turn off the resource when the program exits by adding a close hook.
Use Runtime.addshutdownhook (Thread hook) to add closure hooks to the JVM
Public void Addshutdownhook (Thread hook) { = System.getsecuritymanager (); if NULL { sm.checkpermission (new runtimepermission ("Shutdownhooks")); } Applicationshutdownhooks.add (hook);
Shutdownhook (Thread hook) method, you can register a JVM closed hook, this hook can be called in the following several scenarios:
1) Program Exit normally
2) use System.exit ()
3) interrupts triggered by the terminal using CTRL + C
4) System shutdown
5) Kill the process using the kill PID command
When you do a big task, shut down the JVM. This time, at least the small task that is currently split is completed before it can be closed.
such as bulk queries
Java Close Hook