EJB Timers

The timer service of the enterprise bean container enables you to schedule timed notifications for all types of enterprise beans except for stateful session beans. You can schedule a timed notification to occur according to a calendar schedule, at a specific time, after duration of time, or at timed intervals. For example, you could set timers to go off at 10:30 a.m. on May 23, in 30 days, or every 12 hours.

Enterprise bean timers come in two flavours:

  • Programmatic timers: are explicitly set by calling creation methods from TimerService Interface. Programmatic allow the flexibility to change the values at runtime. @TimedOut method is called when a programmatic timer is fired (on expiry of Timer).
  • Automatic timers: are created using java.ejb.Schedule or java.ejb.Schedule annotations.

Expressions

Attribute
Description
Default Value
Allowable Values and Example
second One or more seconds within a minute. 0 0 to 59. For example: second = "30".
minute One or more minutes within an hour. 0 0 to 59. For example: minute = "15".
hour One or more hours within a day. 0 0 to 23. For example: hour = "13".
dayOfWeek One or more days within a week. * 0 to 7(both 0 and 7 refers to sunday). For example: dayOfWeek = "3".
Sun,Mon,Tue,Wed,Thu,Fri,Sat. For example: dayOfWeek = "Mon".
dayOfMonth One or more days within a month. * 1 to 30. For example: daysOfMonth = "15".
-7 to -1(a negative number means the nth day or days before the end of the month). For example: dayOfMonth = "-3"
Last. For example: dayOfMonth="Last".
[1st,2nd,3rd,4th,5th,Last][Sun,Mon,Tue,Wed,Thu,Fri,Sat]. For example: dayOfMonth = "2nd Fri".
month One or more months within a year. * 1 to 12. For example: month = "7".
[Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]. For example: month = "Mar".
year A particular calendar year * A four-digit calendar year. For example: year = "2011".