Modifier | Constructor and Description |
---|---|
protected |
TimerTask()
Creates a new timer task.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.