Java Reference
In-Depth Information
Unregisters a previously registered virtual machine shutdown
hook. Returns TRue if hook was registered and has been unre-
gistered. Returns false if hook was not previously registered.
You cannot add or remove shutdown hooks after shutdown has com-
menced; you will get IllegalStateException if you try.
When shutdown is initiated, the virtual machine will invoke the start
method on all shutdown hook THRead objects. You cannot rely on any
orderingshutdown hook threads may be executed before, after, or at
the same time as any other shutdown hook thread depending on thread
scheduling.
You must be careful about this lack of ordering. Suppose, for example,
you were writing a class that stored state in a database. You might re-
gister a shutdown hook that closed the database. However, a program
using your class might want to register its own shutdown hook that
writes some final state information through your class to the database.
If your shutdown hook is run first (closing the database), the program's
shutdown hook would fail in writing its final state. You can improve this
situation by writing your class to reopen the database when needed, al-
though this might add complexity to your class and possibly even some
bad race conditions. Or you might design your class so that it doesn't
need any shutdown hooks.
It is also important to realize that the shutdown hook threads will ex-
ecute concurrently with other threads in the system. If shutdown was
initiated because the last user thread terminated, then the shutdown
hook threads will execute concurrently with any daemon threads in the
system. If shutdown was initiated by a call to exit , then the shut-
down hook threads will execute concurrently with both daemon and user
threads. Your shutdown hook threads must be carefully written to en-
sure correct synchronization while avoiding potential deadlocks.
Your shutdown hooks should execute quickly. When users interrupt a
program, for example, they expect the program to terminate quickly.
And when a virtual machine is terminated because a user logs out or the
computer is shut down, the virtual machine may be allowed only a small
 
Search WWH ::




Custom Search