4 Replies Latest reply on May 4, 2007 12:19 PM by mr662

    design pattern for canceling an EJB3 timer

    mr662 Newbie

      I need some advice on how to cancel an active EJB3 timer. Currently below is the flow of things in my application

      1. Client schedules a task via SLSB.
      2. SLSB validates task parameters and queues a JMS msg, passing it the Task Object.
      3. Corresponding MDB gets the JMS message and depending on scheduling params starts a timer for the task.
      4. On timer expiration the @Timeout method on MDB is called, which executes the task

      In between 1 and 4, client my request to cancel this task via SLSB. In this case SLSB will set the 'cancelRequested' flag on the Task Object.

      In 4 above, the MDB @Timeout method checks if the 'cancelRequested' flag is set. If cancel is requested it wouldn't perform the task and if this timer was of a recurring nature it will also cancel the timer.

      Problem is user has to wait till next timer expiration (i.e. until @Timeout method is called) to see if the task was successfully canceled. I need a way to cancel the timer right away when user requests to cancel the task. In order to cancel the timer, I need the TimerHandle. How can I access the TimerHandle to be able to cancel the timer right away?