java::util::TimerTask Class Reference

Inheritance diagram for java::util::TimerTask:

Inheritance graph
java::lang::Runnablejava::lang::Interfacejava::lang::ScopeAdapterjava::lang::Comparablejava::lang::Objectjava::lang::Syncjava::lang::Lock
[legend]
Collaboration diagram for java::util::TimerTask:

Collaboration graph
java::lang::Runnablejava::lang::Interfacejava::lang::ScopeAdapterjava::lang::Comparablejava::lang::Objectjava::lang::ObjectRefjava::lang::Syncjava::lang::Lock
[legend]

List of all members.


Detailed Description

A task that can be scheduled for one-time or repeated execution by a Timer.

Author:
Josh Bloch
Version:
1.7, 12/03/01
See also:
Timer
Since:
1.3

Public Types

enum  TASK_STATE { VIRGIN, SCHEDULED, EXECUTED, CANCELLED }
 The state of this task, chosen from the constants below. More...

Public Member Functions

 TimerTask ()
virtual void run ()=0
 The action to be performed by this timer task.
virtual jint compareTo (const Object &o) const
 Compares this timer task to another Object.
virtual jboolean cancel ()
 Cancels this timer task.
virtual jlong scheduledExecutionTime ()
 Returns the scheduled execution time of the most recent actual execution of this task.

Public Attributes

jint state
jlong nextExecutionTime
jlong period

Member Enumeration Documentation

enum java::util::TimerTask::TASK_STATE

The state of this task, chosen from the constants below.

Enumerator:
VIRGIN  This task has not yet been scheduled.
SCHEDULED  This task is scheduled for execution.

If it is a non-repeating task, it has not yet been executed.

EXECUTED  This non-repeating task has already executed (or is currently executing) and has not been cancelled.
CANCELLED  This task has been cancelled (with a call to TimerTask.cancel).


Constructor & Destructor Documentation

java::util::TimerTask::TimerTask (  ) 


Member Function Documentation

virtual void java::util::TimerTask::run (  )  [pure virtual]

The action to be performed by this timer task.

Implements java::lang::Runnable.

virtual jint java::util::TimerTask::compareTo ( const Object o  )  const [virtual]

Compares this timer task to another Object.

If the Object is a timer task, the comparation is base on the nextExecutionTime of the task or it throw a ClassCastException.

Parameters:
o the Object to be compared.
Returns:
the value 0 if the argument is a timer task equal to this task; a value less than 0 if the argument is a timer task after this task; and a value greater than 0 if the argument is a timer task before this task.
Exceptions:
ClassCastException if the argument is not a TimerTask.
Since:
1.2

Reimplemented from java::lang::Comparable.

virtual jboolean java::util::TimerTask::cancel (  )  [virtual]

Cancels this timer task.

If the task has been scheduled for one-time execution and has not yet run, or has not yet been scheduled, it will never run. If the task has been scheduled for repeated execution, it will never run again. (If the task is running when this call occurs, the task will run to completion, but will never run again.)

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.

Returns:
true if this task is scheduled for one-time execution and has not yet run, or this task is scheduled for repeated execution. Returns false if the task was scheduled for one-time execution and has already run, or if the task was never scheduled, or if the task was already cancelled. (Loosely speaking, this method returns true if it prevents one or more scheduled executions from taking place.)

virtual jlong java::util::TimerTask::scheduledExecutionTime (  )  [virtual]

Returns the scheduled execution time of the most recent actual execution of this task.

(If this method is invoked while task execution is in progress, the return value is the scheduled execution time of the ongoing task execution.)

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.

Returns:
the time at which the most recent execution of this task was scheduled to occur, in the format returned by Date.getTime(). The return value is undefined if the task has yet to commence its first execution.
See also:
Date::getTime()


Member Data Documentation

jint java::util::TimerTask::state

jlong java::util::TimerTask::nextExecutionTime

jlong java::util::TimerTask::period


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:52 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3