public class BACITimer
extends java.lang.Object
EDU.oswego.cs.dl.util.concurrent (it was not approriate for BACI usage).
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.EDU.oswego.cs.dl.util.concurrent| Modifier and Type | Class and Description |
|---|---|
protected class |
BACITimer.RunLoop
The runloop 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.
|
protected static class |
BACITimer.TaskNode |
static interface |
BACITimer.TimerRunnable
Timer runnable interface.
|
| Modifier and Type | Field and Description |
|---|---|
protected Heap |
heap_
tasks are maintained in a standard priority queue
|
protected BACITimer.RunLoop |
runLoop_ |
protected boolean |
shutdown_
shutdown status flag
|
protected java.lang.Thread |
thread_
The thread used to process commands
|
protected java.util.concurrent.ThreadFactory |
threadFactory_
thread factory, can be null
|
| Constructor and Description |
|---|
BACITimer(java.util.concurrent.ThreadFactory threadFactory)
Constructor.
|
| 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
|
java.lang.Object |
executeAfterDelay(long millisecondsToDelay,
BACITimer.TimerRunnable command)
Excecute the given command after waiting for the given delay.
|
java.lang.Object |
executeAt(java.util.Date date,
BACITimer.TimerRunnable command)
Execute the given command at the given time.
|
java.lang.Object |
executePeriodically(long period,
BACITimer.TimerRunnable command,
long firstTime)
Execute the given command every
period milliseconds AT FIXED RATE. |
java.lang.Thread |
getThread()
Return the thread being used to process commands, or
null if there is no such thread.
|
protected BACITimer.TaskNode |
nextTask()
Return the next task to execute, or null if thread is interrupted
|
protected 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.
|
protected final Heap heap_
protected final java.util.concurrent.ThreadFactory threadFactory_
protected volatile boolean shutdown_
protected java.lang.Thread thread_
protected final BACITimer.RunLoop runLoop_
public BACITimer(java.util.concurrent.ThreadFactory threadFactory)
threadFactory - thread factory to be used to create thread, if null no factory is being usedpublic java.lang.Object executeAt(java.util.Date date,
BACITimer.TimerRunnable command)
date - -- the absolute time to run the command, expressed
as a java.util.Date.command - -- the command to run at the given time.public java.lang.Object executeAfterDelay(long millisecondsToDelay,
BACITimer.TimerRunnable command)
millisecondsToDelay - -- the number of milliseconds
from now to run the command.command - -- the command to run after the delay.public java.lang.Object executePeriodically(long period,
BACITimer.TimerRunnable command,
long firstTime)
period milliseconds AT FIXED RATE.
If startNow is true, execution begins immediately,
otherwise, it begins after the first period delay.period - -- the period, in milliseconds. Periods are
measured from start-of-task to the next start-of-task. It is
generally a bad idea to use a period that is shorter than
the expected task duration.command - -- the command to run at each cyclefirstTime - -- time when task should start with execution, 0 means immediately.java.lang.IllegalArgumentException - if period less than or equal to zero.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()
protected void restart()
public void shutDown()
protected BACITimer.TaskNode nextTask()