public class ShutdownHookProcessDestroyer extends java.lang.Object implements ProcessDestroyer, java.lang.Runnable
Process
es when the VM exits.Modifier and Type | Class and Description |
---|---|
private class |
ShutdownHookProcessDestroyer.ProcessDestroyerImpl |
Modifier and Type | Field and Description |
---|---|
private boolean |
added
Whether or not this ProcessDestroyer has been registered as a shutdown hook
|
private ShutdownHookProcessDestroyer.ProcessDestroyerImpl |
destroyProcessThread
The thread registered at the JVM to execute the shutdown handler
|
private java.util.Vector<java.lang.Process> |
processes
the list of currently running processes
|
private boolean |
running
Whether or not this ProcessDestroyer is currently running as shutdown hook
|
Constructor and Description |
---|
ShutdownHookProcessDestroyer()
Constructs a
ProcessDestroyer and obtains
Runtime.addShutdownHook() and
Runtime.removeShutdownHook() through reflection. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Process process)
Returns
true if the specified Process was
successfully added to the list of processes to destroy upon VM exit. |
private void |
addShutdownHook()
Registers this
ProcessDestroyer as a shutdown hook, uses
reflection to ensure pre-JDK 1.3 compatibility. |
boolean |
isAddedAsShutdownHook()
Returns whether or not the ProcessDestroyer is registered as as shutdown
hook
|
boolean |
remove(java.lang.Process process)
Returns
true if the specified Process was
successfully removed from the list of processes to destroy upon VM exit. |
private void |
removeShutdownHook()
Removes this
ProcessDestroyer as a shutdown hook, uses
reflection to ensure pre-JDK 1.3 compatibility |
void |
run()
Invoked by the VM when it is exiting.
|
int |
size()
Returns the number of registered processes.
|
private final java.util.Vector<java.lang.Process> processes
private ShutdownHookProcessDestroyer.ProcessDestroyerImpl destroyProcessThread
private boolean added
private volatile boolean running
public ShutdownHookProcessDestroyer()
ProcessDestroyer
and obtains
Runtime.addShutdownHook()
and
Runtime.removeShutdownHook()
through reflection. The
ProcessDestroyer manages a list of processes to be destroyed when the VM
exits. If a process is added when the list is empty, this
ProcessDestroyer
is registered as a shutdown hook. If
removing a process results in an empty list, the
ProcessDestroyer
is removed as a shutdown hook.private void addShutdownHook()
ProcessDestroyer
as a shutdown hook, uses
reflection to ensure pre-JDK 1.3 compatibility.private void removeShutdownHook()
ProcessDestroyer
as a shutdown hook, uses
reflection to ensure pre-JDK 1.3 compatibilitypublic boolean isAddedAsShutdownHook()
public boolean add(java.lang.Process process)
true
if the specified Process
was
successfully added to the list of processes to destroy upon VM exit.add
in interface ProcessDestroyer
process
- the process to addtrue
if the specified Process
was
successfully addedpublic boolean remove(java.lang.Process process)
true
if the specified Process
was
successfully removed from the list of processes to destroy upon VM exit.remove
in interface ProcessDestroyer
process
- the process to removetrue
if the specified Process
was
successfully removedpublic int size()
size
in interface ProcessDestroyer
public void run()
run
in interface java.lang.Runnable