@javax.ejb.Schedule

From NovaOrdis Knowledge Base
Revision as of 17:00, 25 September 2017 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

External

Internal

Overview

Used by EJB to designate timeout callback methods that will be invoked by automatically-created timers.

Example:

@Schedule(hour="3", dayOfMonth="1", info="something")
public void toBeExecutedAt3AMOnTheFirstDayOfTheMonth() {
   ...
}

Usage Rules

The annotation must be applied to the method implementation, in the bean class. If applied to the method declaration in the interface, it will be ignored.

The method The methods can have any access level, but must not be final or static, and must not throw application exceptions. An EJB can have any number of automatically created timers.

The container interleaves calls to timeout callbacks with calls to business methods and lifecycle callbacks, so the time at which a timeout callback is called may occur after the timer fired. If multiple timers fire at approximately the same time, callbacks may be out of sequence.

Configuration

The annotation is configured using a cron-like time expression, using the following attributes:

  • second (if not specified, default is 0)
  • minute (if not specified, default is 0)
  • hour (if not specified, default is 0)
  • dayOfMonth
  • month
  • dayOfWeek
  • year

If you intend to test a time firing every other few seconds, make sure to specify hour="*" and minute="*". If they are not specified, the default values are 0 and 0, respectively, which means your timer will start firing at midnight next day, for maximum a minute.

The following example fires a timer every 20 seconds, continuously:

@Schedule(hour="*", minute="*", second = "0/20")
public void fireEvery20SecsContinously() {
   ...
}