A Java Virtual Machine terminates all its activity and exits when one of two things happens:
exit
method (§20.16.2) of class Runtime
or class System
and the exit operation is not forbidden by the security manager (§20.17.13).
A Java program can specify that the finalizers of all objects that have finalizers,
and all classes that have class finalizers, that have not yet been automatically
invoked are to be run before the virtual machine exits. This is done by invoking
the method runFinalizersOnExit
of class System
with the argument true
. The
default is to not run finalizers on exit, and this behavior may be restored by invoking runFinalizersOnExit
with the argument false
. An invocation of the runFinalizersOnExit
method is permitted only if the caller is allowed to exit
, and
is otherwise rejected by the SecurityManager
(§20.17).
. . . Farewell!
The day frowns more and more. Thou'rt like to have
A lullaby too rough: I never saw
The heavens so dim by day: A savage clamour!
Well may I get aboard! This is the chase.
I am gone for ever! [Exit, pursued by a bear]
William Shakespeare, The Winter's Tale, Act III, scene iii