Enterprise Java Development@TOPIC@

Chapter 127. EJB Timers Overview

127.1. EJB Timer History
127.2. EJB Timer Service
127.3. Single Action EJB Timers
127.4. Interval EJB Timers
127.5. Calendar EJB Timers
127.6. EJB Timer Summary
import javax.annotation.Resource;

import javax.ejb.TimerService;
@Resource

private TimerService timerService;
  • Starting point for all EJB Timer programmatic manipulation

    • Timer Creation

      • createCalendarTimer(ScheduleExpression schedule, ...)

      • createIntervalTimer(Date initialExpiration, long intervalDuration, ...)

      • createSingleActionTimer(Date expiration, ...)

    • Get Timers

      • getTimers() - get Timers associated with this EJB

      • getAllTimers() - get Timers associated with this module

    Start by creating non-persistent Timers

    EJB Timers are created as perisistent=true by default. This sounds reasonable until you begin refactoring your application and start seeing "EJB not found", etc. on follow-on redeploys or many more EJB Timers firing that you believe should be. For programmatic EJB Timers - always pass in the optional TimerConfig and set persistent to false. For the Schedule annotation, set the persistent attribute to false.

    It is always desirable to be able to easily coldstart your application in development with a reboot of the application server or a redeploy of the application and not have to worry about artifacts of a previous implementation approach.

createSingleActionTimer(Date expiration, TimerConfig timerConfig)

createSingleActionTimer(long duration, TimerConfig timerConfig)
createIntervalTimer(Date initialExpiration, long intervalDuration, TimerConfig timerConfig)

createIntervalTimer(long initialDuration, long intervalDuration, TimerConfig timerConfig)
createCalendarTimer(ScheduleExpression schedule, TimerConfig timerConfig)