Class TimerTask

java.lang.Object
org.jboss.as.ejb3.timerservice.TimerTask
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
CalendarTimerTask

public class TimerTask extends Object implements Runnable
A timer task which will be invoked at appropriate intervals based on a Timer schedule.

A TimerTask is responsible for invoking the timeout method on the target, through the use of TimedObjectInvoker

For calendar timers, this TimerTask is additionally responsible for creating and scheduling the next round of timer task.

Version:
$Revision: $
Author:
Jaikiran Pai, Wolf-Dieter Fink
  • Field Details

  • Constructor Details

    • TimerTask

      public TimerTask(TimerImpl timer)
      Creates a TimerTask for the timer
      Parameters:
      timer - The timer for which this task is being created.
      Throws:
      IllegalStateException - If the passed timer is null
  • Method Details

    • run

      public void run()
      Invokes the timeout method through the TimedObjectInvoker corresponding to the TimerImpl to which this TimerTask belongs.

      This method also sets other attributes on the TimerImpl including the next timeout of the timer and the timer state.

      Additionally, for calendar timers, this method even schedules the next timeout timer task before calling the timeout method for the current timeout.

      Specified by:
      run in interface Runnable
    • scheduleTimeoutIfRequired

      protected void scheduleTimeoutIfRequired(TimerImpl timer)
    • callTimeout

      protected void callTimeout(TimerImpl timer) throws Exception
      Throws:
      Exception
    • invokeBeanMethod

      protected void invokeBeanMethod(TimerImpl timer) throws Exception
      Throws:
      Exception
    • calculateNextTimeout

      protected Date calculateNextTimeout(TimerImpl timer)
    • retryTimeout

      protected void retryTimeout(TimerImpl timer) throws Exception
      After a timeout failed the timer need to retried. The method must lock the timer for state check and update but not during callTimeout run.
      Parameters:
      timer - timer to retry and state updates
      Throws:
      Exception
    • postTimeoutProcessing

      protected void postTimeoutProcessing(TimerImpl timer) throws InterruptedException
      After running the timer calculate the new state or expire the timer and persist it if changed. The method must lock the timer for state check and updates if overridden.
      Parameters:
      timer - timer to post processing and persist
      Throws:
      InterruptedException
    • cancel

      public void cancel()