|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
net.sourceforge.jtds.util.TimerThread
public class TimerThread
Simple timer class used to implement login and query timeouts.
This thread runs as a Daemon thread to ensure that the java VM will exit correctly when normal execution is complete. It provides both a singleton implementation and a default constructor for the case when more than one timer thread is desired.
| Nested Class Summary | |
|---|---|
static interface |
TimerThread.TimerListener
Interface to be implemented by classes that request timer services. |
private static class |
TimerThread.TimerRequest
Internal class associating a login or query timeout value with a target TimerListener. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
private static TimerThread |
instance
Singleton instance. |
private long |
nextTimeout
Time when the first request time out should occur. |
private java.util.LinkedList |
timerList
List of TimerRequests to execute, ordered by time. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
TimerThread()
Construct a new TimerThread instance. |
|
| Method Summary | |
|---|---|
boolean |
cancelTimer(java.lang.Object handle)
Remove a redundant timer before it expires. |
static TimerThread |
getInstance()
Singleton getter. |
boolean |
hasExpired(java.lang.Object handle)
Check whether a timer has expired. |
void |
run()
Execute the TimerThread main loop. |
java.lang.Object |
setTimer(int timeout,
TimerThread.TimerListener l)
Add a timer request to the queue. |
private void |
updateNextTimeout()
Internal method that updates the value of nextTimeout. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, 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 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static TimerThread instance
private final java.util.LinkedList timerList
TimerRequests to execute, ordered by time.
private long nextTimeout
| Constructor Detail |
|---|
public TimerThread()
TimerThread instance.
| Method Detail |
|---|
public static TimerThread getInstance()
public void run()
TimerThread main loop.
run in interface java.lang.Runnablerun in class java.lang.Thread
public java.lang.Object setTimer(int timeout,
TimerThread.TimerListener l)
timeout - the interval in milliseconds after which the timer will
expirel - TimerListener to be notified on timeout
cancelTimerpublic boolean cancelTimer(java.lang.Object handle)
handle - handle to the request to be removed from the queue (a
TimerRequest instance)
true if timer had not expiredpublic boolean hasExpired(java.lang.Object handle)
handle - handle to the request to be checked for expiry (a
TimerRequest instance)
true if timer has expiredprivate void updateNextTimeout()
nextTimeout.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||