Hooks to be started and does not run uninvoked finalizers ifįinalization-on-exit has been enabled. Unlike theĮxit method, this method does not cause shutdown This method should be used with extreme caution. removeShutdownHook public boolean removeShutdownHook( Thread hook)įorcibly terminates the currently running Java virtual machine.RuntimePermission("shutdownHooks") Since: 1.3 See Also: removeShutdownHook(), Of shutting down SecurityException - If a security manager is present and it denies Has already been run IllegalStateException - If the virtual machine is already in the process Or if it can be determined that the hook is already running or Parameters: hook - An initialized but unstarted Thread object Throws: IllegalArgumentException - If the specified hook has already been registered, Then no guarantee can be made about whether or not any shutdown hooks Method goes awry by, for example, corrupting internal data structures orĪttempting to access nonexistent memory. The virtual machine may also abort if a native SIGKILL signal on Unix or the TerminateProcess call on Virtual machine is terminated externally, for example with the Stop running without shutting down cleanly. In rare circumstances the virtual machine may abort, that is, Terminates the thread it does not cause the virtual machine to exit or Prints the exception's stack trace to System.err and The default implementation of this method Other thread, by invoking the uncaughtException method of the thread's ThreadGroup object. Uncaught exceptions are handled in shutdown hooks just as in any User interaction or to perform a long-running computation in a shutdown It is therefore inadvisable to attempt any Underlying operating system may only allow a fixed amount of time in Virtual machine is terminated due to user logoff or system shutdown the That the virtual machine will promptly shut down and exit. Shutdown hooks should also finish their work quickly. Services such as the AWT event-dispatch thread, for example, may lead to Have registered their own shutdown hooks and therefore may themselves in They should also not rely blindly upon services that may Particular, be written to be thread-safe and to avoid deadlocks insofarĪs possible.
Machine and should therefore be coded defensively. Shutdown hooks run at a delicate time in the life cycle of a virtual New shutdown hook or de-register a previously-registered hook.Īttempting either of these operations will cause an Once the shutdown sequence has begun it is impossible to register a Once the shutdown sequence has begun it can be stopped only by If shutdown was initiated by invoking the exit Note that daemon threads willĬontinue to run during the shutdown sequence, as will non-daemon threads Run all uninvoked finalizers if finalization-on-exit has been enabled.įinally, the virtual machine will halt. When all the hooks have finished it will then Start all registered shutdown hooks in some unspecified order and let When the virtual machine begins its shutdown sequence it will User interrupt, such as typing ^C, or a system-wide event,Ī shutdown hook is simply an initialized but unstarted
Java runtime environment code#
With the given status code if the status is nonzero otherwise, itĬonventional and convenient means of invoking this method. If shutdown hooks have already been run and on-exitįinalization has been enabled then this method halts the virtual machine Shutdown sequence then if shutdown hooks are being run this method willīlock indefinitely. If this method is invoked after the virtual machine has begun its Once this is done the virtual machine halts. In the second phase all uninvokedįinalizers are run if finalization-on-exit If any, are started in some unspecified order and allowed to runĬoncurrently until they finish. The first phase all registered shutdown hooks, The virtual machine's shutdown sequence consists of two phases. Serves as a status code by convention, a nonzero status code indicates Terminates the currently running Java virtual machine by initiating its