Last active
December 27, 2019 12:57
-
-
Save nbhusare/126808b05cb7266bb0f690ac9b34fbdf to your computer and use it in GitHub Desktop.
Add a new Virtual Machine Shutdown hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | |
// Your code comes here... | |
})); | |
/* addShutdownHook() - A shutdown hook is simply an initialized but unstarted thread. When the virtual machine begins its | |
shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run concurrently. When all the | |
hooks have finished it will then run all uninvoked finalizers if finalization-on-exit has been enabled. Finally, the virtual machine | |
will halt. Note that daemon threads will continue to run during the shutdown sequence, as will non-daemon threads if shutdown was | |
initiated by invoking the exitmethod. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment