FileDocCategorySizeDatePackage
TimerTask.javaAPI DocExample2413Sat Jan 24 10:44:26 GMT 2004je3.thread

TimerTask

public abstract class TimerTask extends Object implements Runnable
This class implements the same API as the Java 1.3 java.util.TimerTask. Note that a TimerTask can only be scheduled on one Timer at a time, but that this implementation does not enforce that constraint.

Fields Summary
boolean
cancelled
long
nextTime
long
period
boolean
fixedRate
Constructors Summary
protected TimerTask()

            // Fixed-rate execution?

      
Methods Summary
public booleancancel()
Cancel the execution of the task. Return true if it was actually running, or false if it was already cancelled or never scheduled.

	if (cancelled) return false;         // Already cancelled;
	cancelled = true;                    // Cancel it
	if (nextTime == -1) return false;    // Never scheduled;
	return true;
    
booleanreschedule()

	if (period == 0 || cancelled) return false; // Don't run it again
	if (fixedRate) nextTime += period;
	else nextTime = System.currentTimeMillis() + period;
	return true;
    
public abstract voidrun()
Subclasses must override this to provide that code that is to be run. The Timer class will invoke this from its internal thread.

voidschedule(long nextTime, long period, boolean fixedRate)

	this.nextTime = nextTime;
	this.period = period;
	this.fixedRate = fixedRate;
    
public longscheduledExecutionTime()
When it the timer scheduled to execute? The run() method can use this to see whether it was invoked when it was supposed to be

 return nextTime;