Possible Duplicate:
When Shutdown Hooks Break Bad
I want to know if shutdownhook is guaranteed to execute in the scenario if JVM crashes.
When the JRockit JVM crashes, it generates a binary crash file ( . core or . mdmp ). By default, the binary crash file contains a copy of the entire JVM process.
Shutdown Hooks are a special construct that allows developers to plug in a piece of code to be executed when the JVM is shutting down. This comes in handy in cases where we need to do special clean up operations in case the VM is shutting down.
The Runtime. halt() can stop the shutdown sequence that has been started: Only the Runtime. halt(), which terminates the JVM forcefully, can stop the started shutdown sequence, which also means that invoking the System. exit() method will not work within a shutdown hook.
To crash a JVM, aside from JNI, you need to find a bug in the VM itself. An infinite loop just consumes CPU. Infinitely allocating memory should just cause OutOfMemoryError's in a well built JVM. This would probably cause problems for other threads, but a good JVM still should not crash.
Nope. From the docs:
In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the SIGKILL signal on Unix or the TerminateProcess call on Microsoft Windows. The virtual machine may also abort if a native method goes awry by, for example, corrupting internal data structures or attempting to access nonexistent memory. If the virtual machine aborts then no guarantee can be made about whether or not any shutdown hooks will be run.
(emphasis mine)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With