public abstract class RecurringTask<T extends ExecutionContext>
extends java.lang.Object
Constructor and Description |
---|
RecurringTask()
Construct a RecurringTask that should execute roughly once per second.
|
RecurringTask(long interval)
Construct a RecurringTask that will execute roughly once every
interval milliseconds. |
RecurringTask(java.util.concurrent.TimeUnit timeUnit)
Construct a RecurringTask that should execute roughly once per the time unit specified.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel this task; after this method is called, the task will not be run again.
|
abstract void |
execute(T context)
This method is invoked by the execution thread when at least the number of milliseconds specified by
getInterval have passed since the last time it was executed. |
long |
getInterval() |
boolean |
isCancelled() |
boolean |
isPaused() |
boolean |
isSkipped() |
void |
pause()
Pause this task; it will not be executed again until it is resumed.
|
void |
resume()
Resume this task; if it is currently paused, it will begin executing at it's regular interval again.
|
void |
skip()
Skip the next execution of this task.
|
public RecurringTask()
public RecurringTask(java.util.concurrent.TimeUnit timeUnit)
timeUnit
- The time unit that should pass between each execution. Note that no time unit will ever cause
this task to be executed faster that once per millisecond. Also note that this specifies the minimum
unit of time that must pass before the next time this task executes.public RecurringTask(long interval)
interval
milliseconds.interval
- The number of milliseconds that should have passed between executions of this task. Note that
is the minimum number of milliseconds; more may pass between each execution.public final long getInterval()
public abstract void execute(T context)
getInterval
have passed since the last time it was executed.context
- The ExecutionContext provided to this RecurringTask, specific to the execution thread on which it
was scheduled.public void cancel()
public boolean isCancelled()
public boolean isPaused()
public boolean isSkipped()
public void pause()
public void resume()
public void skip()