java.util
abstract public class: TimerTask [javadoc |
source]
java.lang.Object
java.util.TimerTask
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
The {@code TimerTask} class represents a task to run at a specified time. The task
may be run once or repeatedly.
Also see:
- Timer
- java.lang.Object#wait(long)
| Field Summary |
|---|
| final Object | lock | |
| boolean | cancelled | |
| long | when | |
| long | period | |
| boolean | fixedRate | |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from java.util.TimerTask Detail: |
public boolean cancel() {
synchronized (lock) {
boolean willRun = !cancelled && when > 0;
cancelled = true;
return willRun;
}
}
Cancels the {@code TimerTask} and removes it from the {@code Timer}'s queue. Generally, it
returns {@code false} if the call did not prevent a {@code TimerTask} from running at
least once. Subsequent calls have no effect. |
long getWhen() {
synchronized (lock) {
return when;
}
}
|
boolean isScheduled() {
synchronized (lock) {
return when > 0 || scheduledTime > 0;
}
}
|
abstract public void run()
The task to run should be specified in the implementation of the {@code run()}
method. |
public long scheduledExecutionTime() {
synchronized (lock) {
return scheduledTime;
}
}
Returns the scheduled execution time. If the task execution is in
progress it returns the execution time of the ongoing task. Tasks which
have not yet run return an undefined value. |
void setScheduledTime(long time) {
synchronized (lock) {
scheduledTime = time;
}
}
|