Package org.jboss.util
Class TimerTask
- java.lang.Object
-
- org.jboss.util.TimerTask
-
- All Implemented Interfaces:
java.lang.Comparable,Executable
public abstract class TimerTask extends java.lang.Object implements Executable, java.lang.Comparable
A class that represent a task that can be scheduled for one-shot or repeated execution by aTimerQueue.A similar class is present in java.util package of jdk version >= 1.3; for compatibility with jdk 1.2 we reimplemented it.
- Version:
- $Revision$
- See Also:
TimerQueue
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intCANCELLEDThe state when cancelled(package private) static intEXECUTEDThe state after first execution if the TimerTask is not repeatingprivate java.lang.Objectm_lockprivate longm_nextExecutionTimeprivate longm_periodprivate intm_state(package private) static intNEWThe state before the first execution(package private) static intSCHEDULEDThe state after first execution if the TimerTask is repeating
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancancel()Cancels the next execution of this TimerTask (if any).intcompareTo(java.lang.Object other)A TimerTask is less than another if it will be scheduled before.abstract voidexecute()The task to be executed, to be implemented in subclasses.(package private) java.lang.ObjectgetLock()Returns the mutex that syncs the access to this object(package private) longgetNextExecutionTime()Returns the next execution time for this TimerTaskprotected longgetPeriod()(package private) intgetState()Returns the state of execution of this TimerTask(package private) booleanisPeriodic()Returns whether this TimerTask is periodic(package private) voidsetNextExecutionTime(long time)Sets the next execution time for this TimerTask(package private) voidsetState(int state)Sets the state of execution of this TimerTask
-
-
-
Field Detail
-
NEW
static final int NEW
The state before the first execution- See Also:
- Constant Field Values
-
SCHEDULED
static final int SCHEDULED
The state after first execution if the TimerTask is repeating- See Also:
- Constant Field Values
-
EXECUTED
static final int EXECUTED
The state after first execution if the TimerTask is not repeating- See Also:
- Constant Field Values
-
CANCELLED
static final int CANCELLED
The state when cancelled- See Also:
- Constant Field Values
-
m_lock
private final java.lang.Object m_lock
-
m_state
private int m_state
-
m_period
private final long m_period
-
m_nextExecutionTime
private long m_nextExecutionTime
-
-
Constructor Detail
-
TimerTask
protected TimerTask()
Creates a TimerTask object that will be executed once.
-
TimerTask
protected TimerTask(long period)
Creates a TimerTask object that will be executed everyperiodmilliseconds.- Parameters:
period- the execution period; if zero, will be executed only once.
-
-
Method Detail
-
cancel
public boolean cancel()
Cancels the next execution of this TimerTask (if any).
If the TimerTask is executing it will prevent the next execution (if any).- Returns:
- true if one or more scheduled execution will not take place, false otherwise.
-
execute
public abstract void execute() throws java.lang.ExceptionThe task to be executed, to be implemented in subclasses.- Specified by:
executein interfaceExecutable- Throws:
java.lang.Exception
-
compareTo
public int compareTo(java.lang.Object other)
A TimerTask is less than another if it will be scheduled before.- Specified by:
compareToin interfacejava.lang.Comparable- Throws:
java.lang.ClassCastException- if other is not a TimerTask, according to the Comparable contract
-
getLock
java.lang.Object getLock()
Returns the mutex that syncs the access to this object
-
setState
void setState(int state)
Sets the state of execution of this TimerTask
-
getState
int getState()
Returns the state of execution of this TimerTask
-
isPeriodic
boolean isPeriodic()
Returns whether this TimerTask is periodic
-
getNextExecutionTime
long getNextExecutionTime()
Returns the next execution time for this TimerTask
-
setNextExecutionTime
void setNextExecutionTime(long time)
Sets the next execution time for this TimerTask
-
getPeriod
protected long getPeriod()
- Returns:
- the period of this TimerTask
-
-