commonj.timers
Interface Timer


public interface Timer

An object implementing this interface is returned when an timer is created through one of the TimerManager.schedule methods. It allows the timer to be manipulated and allows it to be reset to fire at another time.

Timers are transient and not transactional and run inside the JVM which created them. If a cluster-wide scheduled event is required or it needs to be persistent, transactional or recoverable then a service such as the EJB 2.1 Timer service should be used instead.

See Also:
Timer, TimerListener

Method Summary
 boolean cancel()
          This cancels the timer.
 long getPeriod()
          Return the period used to compute the next time this timer will expire.
 TimerListener getTimerListener()
          Returns the application-supplied TimerListener associated with this Timer.
 long scheduledExecutionTime()
          This returns the absolute time this timer will expire next.
 

Method Detail

cancel

public boolean cancel()
This cancels the timer. It also can be called during the TimerListener.timerExpired method.

Once cancel is called then an application must not use the timer instance again.

If the owning scope (application) was destroyed then this method does not throw IllegalState as the timer is already cancelled.

Returns:
true if this prevented the next execution of this timer. False if this was already cancelled/stopped or had already expired in the one shot case.

getTimerListener

public TimerListener getTimerListener()
Returns the application-supplied TimerListener associated with this Timer.

Returns:
The TimerListener associated with the timer.

scheduledExecutionTime

public long scheduledExecutionTime()
This returns the absolute time this timer will expire next.

Returns:
the time in milliseconds at which the Timer will expire next.

getPeriod

public long getPeriod()
Return the period used to compute the next time this timer will expire. A value of zero indicates that the timer is non-repeating. A negative value means the next timeout is computed from the current timeout. Positive values mean the timeout is computed using the current timer after the listener has executed.

Returns:
the period used to reset the timer.


Copyright BEA Systems, Inc. and International Business Machines Corp 2003. All rights reserved.