public class WatchdogTimer
extends java.lang.Thread
System.exit()
. This
is useful to cleanup a process which is waiting for a connection that never arrives.
The thread should only be started when the process is in a state where it should be exited at the end of the timeout.
IMPORTANT: Do not use logging anywhere inside this class. When an authentication plugin is running during session establishment with the P2J server using logging no messages are written into the log and the application becomes deadlocked.
Modifier and Type | Field and Description |
---|---|
private static long |
ONE_MINUTE
One minute in milliseconds.
|
private boolean |
running
Flag to control thread abort.
|
private long |
startTime
System time when started.
|
private long |
timeout
Time out value in milliseconds.
|
private static long |
WAIT_TO_DIE
Time to wait for thread exit.
|
Constructor and Description |
---|
WatchdogTimer(long timeout)
Create a new instance and start the timer thread.
|
Modifier and Type | Method and Description |
---|---|
void |
kill()
Terminate the watchdog timer thread.
|
void |
run()
Because the Thread.sleep time is not guaranteed to be accurate, the elapsed time is
calculated once per minute.
|
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
private static final long WAIT_TO_DIE
private static final long ONE_MINUTE
private volatile long startTime
private volatile long timeout
private volatile boolean running
public WatchdogTimer(long timeout)
timeout
- The time out value in milliseconds.public void run()
System.exit()
). Any spurious wake-ups
are avoided using a loop condition.run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void kill()