public class SearchTimer
extends java.lang.Thread
EDU.oswego.cs.dl.util.concurrent. Timer tasks
should complete quickly. If a timer task takes excessive time to complete, it
"hogs" the timer's task execution thread. This can, in turn, delay the
execution of subsequent tasks, which may "bunch up" and execute in rapid
succession when (and if) the offending task finally completes.| Modifier and Type | Class and Description |
|---|---|
static class |
SearchTimer.Heap
A heap-based priority queue.
|
protected class |
SearchTimer.RunLoop
The run loop is isolated in its own Runnable class just so that the main
class need not implement Runnable, which would allow others to directly
invoke run, which is not supported.
|
static class |
SearchTimer.TimerTask |
| Modifier and Type | Field and Description |
|---|---|
protected SearchTimer.Heap |
heap
Tasks are maintained in a standard priority queue.
|
protected SearchTimer.RunLoop |
runLoop |
protected java.lang.Thread |
thread
The thread used to process commands
|
| Constructor and Description |
|---|
SearchTimer()
Protected constructor (singleton pattern).
|
| Modifier and Type | Method and Description |
|---|---|
static void |
cancel(java.lang.Object taskID)
Cancel a scheduled task that has not yet been run.
|
protected void |
clearThread()
set thread to null to indicate termination
|
void |
executeAfterDelay(long millisecondsToDelay,
SearchTimer.TimerTask task)
Execute the given command after waiting for the given delay.
|
java.lang.Thread |
getThread() |
boolean |
hasNext(long dT)
Check whether there is a task scheduled in next "dT" ms.
|
protected SearchTimer.TimerTask |
nextTask(boolean blockAndExtract,
long dt)
Return the next task to execute, or null if thread is interrupted.
|
void |
rescheduleAllAfterDelay(long millisecondsToDelay) |
void |
restart()
Start (or restart) a thread to process commands, or wake up an existing
thread if one is already running.
|
void |
shutDown()
Cancel all tasks and interrupt the background thread executing the
current task, if any.
|
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, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldprotected final SearchTimer.Heap heap
protected final SearchTimer.RunLoop runLoop
protected java.lang.Thread thread
public void executeAfterDelay(long millisecondsToDelay,
SearchTimer.TimerTask task)
millisecondsToDelay - -- the number of milliseconds from now to run the command.task - -- timer taskpublic void rescheduleAllAfterDelay(long millisecondsToDelay)
public static void cancel(java.lang.Object taskID)
taskID - -- a task reference returned by one of the execute commandsjava.lang.ClassCastException - if the taskID argument is not of the type returned by an
execute command.public java.lang.Thread getThread()
protected void clearThread()
public void restart()
public void shutDown()
protected SearchTimer.TimerTask nextTask(boolean blockAndExtract, long dt)
blockAndExtract - block and extractdt - dtpublic boolean hasNext(long dT)
dT - dT