public final class Task extends Object
Task can be started at a given time in the
future and can be a daemon. The block of code will be passed a Log object each time
it is run through its ICode interface.
If the code block takes longer than the period to run, the next task invocation will occur immediately. In this case, tasks will not occur at precise multiples of the period. For example, if you run a task every 30 seconds, and the first run takes 40 seconds but the second takes 20 seconds, your task will be invoked at 0 seconds, 40 seconds and 70 seconds (40 seconds + 30 seconds), which is not an even multiple of 30 seconds.
In general, this is a simple task class designed for polling activities. If you need precise guarantees, you probably should be using a different task class.
| Modifier and Type | Method and Description |
|---|---|
protected org.slf4j.Logger |
getLog()
Gets the log for this
Task. |
int |
getPriority()
Gets the thread priority
|
void |
interrupt()
Interrupts the
Task as soon as it has the opportunity. |
void |
run(Duration frequency,
ICode code)
Runs this
Task at the given frequency. |
void |
setDaemon(boolean daemon)
Sets daemon or not.
|
void |
setLog(org.slf4j.Logger log)
Sets log for user code to log to when task runs.
|
void |
setPriority(int prio)
Sets the priority of the thread
|
void |
setStartTime(Time startTime)
Sets start time for this task.
|
void |
stop()
Stops this
Task as soon as it has the opportunity. |
String |
toString() |
public Task(String name)
name - the name of this Taskpublic final void run(Duration frequency, ICode code)
Task at the given frequency. You may only call this method if the task
has not yet been started. If the task is already running, an
IllegalStateException will be thrown.frequency - the frequency at which to run the codecode - the code to runIllegalStateException - thrown if task is already runningpublic void setDaemon(boolean daemon)
IllegalStateException will be thrown.daemon - true if this Task's Thread should be a
daemonIllegalStateException - thrown if task is already runningpublic void setLog(org.slf4j.Logger log)
log - the logpublic void setStartTime(Time startTime)
startTime - The time this task should start runningIllegalStateException - Thrown if task is already runningpublic String toString()
toString in class ObjectObject.toString()protected org.slf4j.Logger getLog()
Task.public void stop()
Task as soon as it has the opportunity.public void interrupt()
Task as soon as it has the opportunity.public void setPriority(int prio)
prio - public int getPriority()
Copyright © 2006–2015 Apache Software Foundation. All rights reserved.