|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.TimerTask
A task that can be scheduled for one-time or repeated execution by a Timer.
Timer
Field Summary | |
(package private) static int |
CANCELLED
This task has been cancelled (with a call to TimerTask.cancel). |
(package private) static int |
EXECUTED
This non-repeating task has already executed (or is currently executing) and has not been cancelled. |
(package private) Object |
lock
This object is used to control access to the TimerTask internals. |
(package private) long |
nextExecutionTime
Next execution time for this task in the format returned by System.currentTimeMillis, assuming this task is schedule for execution. |
(package private) long |
period
Period in milliseconds for repeating tasks. |
(package private) static int |
SCHEDULED
This task is scheduled for execution. |
(package private) int |
state
The state of this task, chosen from the constants below. |
(package private) static int |
VIRGIN
This task has not yet been scheduled. |
Constructor Summary | |
protected |
TimerTask()
Creates a new timer task. |
Method Summary | |
boolean |
cancel()
Cancels this timer task. |
abstract void |
run()
The action to be performed by this timer task. |
long |
scheduledExecutionTime()
Returns the scheduled execution time of the most recent actual execution of this task. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
final Object lock
int state
static final int VIRGIN
static final int SCHEDULED
static final int EXECUTED
static final int CANCELLED
long nextExecutionTime
long period
Constructor Detail |
protected TimerTask()
Method Detail |
public abstract void run()
run
in interface Runnable
Thread.run()
public boolean cancel()
Note that calling this method from within the run method of a repeating timer task absolutely guarantees that the timer task will not run again.
This method may be called repeatedly; the second and subsequent calls have no effect.
public long scheduledExecutionTime()
This method is typically invoked from within a task's run method, to determine whether the current execution of the task is sufficiently timely to warrant performing the scheduled activity:
public void run() { if (System.currentTimeMillis() - scheduledExecutionTime() >= MAX_TARDINESS) return; // Too late; skip this execution. // Perform the task }This method is typically not used in conjunction with fixed-delay execution repeating tasks, as their scheduled execution times are allowed to drift over time, and so are not terribly significant.
Date.getTime()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |