public abstract class TimerTask extends java.lang.Object implements Executable, java.lang.Comparable
TimerQueue. A similar class is present in java.util package of jdk version >= 1.3; for compatibility with jdk 1.2 we reimplemented it.
TimerQueue| Modifier and Type | Field and Description |
|---|---|
(package private) static int |
CANCELLED
The state when cancelled
|
(package private) static int |
EXECUTED
The state after first execution if the TimerTask is not repeating
|
private java.lang.Object |
m_lock |
private long |
m_nextExecutionTime |
private long |
m_period |
private int |
m_state |
(package private) static int |
NEW
The state before the first execution
|
(package private) static int |
SCHEDULED
The state after first execution if the TimerTask is repeating
|
| Modifier | Constructor and Description |
|---|---|
protected |
TimerTask()
Creates a TimerTask object that will be executed once.
|
protected |
TimerTask(long period)
Creates a TimerTask object that will be executed every
period
milliseconds. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel()
Cancels the next execution of this TimerTask (if any).
|
int |
compareTo(java.lang.Object other)
A TimerTask is less than another if it will be scheduled before.
|
abstract void |
execute()
The task to be executed, to be implemented in subclasses.
|
(package private) java.lang.Object |
getLock()
Returns the mutex that syncs the access to this object
|
(package private) long |
getNextExecutionTime()
Returns the next execution time for this TimerTask
|
protected long |
getPeriod() |
(package private) int |
getState()
Returns the state of execution of this TimerTask
|
(package private) boolean |
isPeriodic()
Returns whether this TimerTask is periodic
|
(package private) void |
setNextExecutionTime(long time)
Sets the next execution time for this TimerTask
|
(package private) void |
setState(int state)
Sets the state of execution of this TimerTask
|
static final int NEW
static final int SCHEDULED
static final int EXECUTED
static final int CANCELLED
private final java.lang.Object m_lock
private int m_state
private final long m_period
private long m_nextExecutionTime
protected TimerTask()
protected TimerTask(long period)
period
milliseconds. period - the execution period; if zero, will be executed only once.public boolean cancel()
public abstract void execute()
throws java.lang.Exception
execute in interface Executablejava.lang.Exceptionpublic int compareTo(java.lang.Object other)
compareTo in interface java.lang.Comparablejava.lang.ClassCastException - if other is not a TimerTask, according to the Comparable contractjava.lang.Object getLock()
void setState(int state)
int getState()
boolean isPeriodic()
long getNextExecutionTime()
void setNextExecutionTime(long time)
protected long getPeriod()