org.rhq.enterprise.agent
Class AgentShutdownHook
java.lang.Object
java.lang.Thread
org.rhq.enterprise.agent.AgentShutdownHook
- All Implemented Interfaces:
- Runnable
public class AgentShutdownHook
- extends Thread
Provides a way to gracefully shutdown the agent. This can be used
as a shutdown hook, and it can also be used to perform some shutdown
functions, like attempting to interrupt hanging threads.
- Author:
- John Mazzitelli
|
Method Summary |
List<Thread> |
interruptAllThreads()
We need to make sure our VM can die quickly, so this method will send interrupts
to most of the threads running in the VM to try to get them to hurry up and die. |
void |
run()
This is executed when the VM is shutting down. |
void |
spawnKillThread(long doomsday)
If something goes wrong and the VM does not die on its own when we think it should,
the thread created by this method will explicitly kill the VM. |
int |
waitForNonDaemonThreads()
If you want the current agent to be dead this method will attept to wait for all
other non-daemon threads to die before returning. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
AgentShutdownHook
public AgentShutdownHook(AgentMain agent)
- Constructor for
AgentShutdownHook that retains the reference to the agent that will be shutdown when
the shutdown hook is triggered.
- Parameters:
agent - the agent to be shutdown when shutdown hook is triggered.
run
public void run()
- This is executed when the VM is shutting down.
- Specified by:
run in interface Runnable- Overrides:
run in class Thread
waitForNonDaemonThreads
public int waitForNonDaemonThreads()
- If you want the current agent to be dead this method will attept to wait for all
other non-daemon threads to die before returning.
We log messages if we can't wait for them all for whatever reason.
Note that obviously this method will not wait for the calling thread
that is currently running this method.
- Returns:
- the number of still active non-daemon threads that haven't died even after waiting
interruptAllThreads
public List<Thread> interruptAllThreads()
- We need to make sure our VM can die quickly, so this method will send interrupts
to most of the threads running in the VM to try to get them to hurry up and die.
- Returns:
- the non-daemon threads that were interrupted
spawnKillThread
public void spawnKillThread(long doomsday)
- If something goes wrong and the VM does not die on its own when we think it should,
the thread created by this method will explicitly kill the VM.
Calling this method sets a timebomb that will kill the VM after a timer runs out.
There is no way to stop this timebomb short of performing 007-type heroics.
- Parameters:
doomsday - the number of milliseconds that the VM has left to live; once this
time expires, a kill thread will execute System.exit(0).
Copyright © 2008-2011 Red Hat, Inc.. All Rights Reserved.