@javax.ejb.Schedule: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 20: Line 20:
}
}
</syntaxhighlight>
</syntaxhighlight>
=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 methods must have the following signatures;
void ''method_name''()
void ''method_name''(Timer timer)
A timeout callback method can have public, private, protected, or package level access. It must not be declared as final or static. It must not throw application exceptions.
An EJB can have any number of automatically created timers.


=Configuration=
=Configuration=

Latest revision as of 17:05, 25 September 2017

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 methods must have the following signatures;

void method_name()
void method_name(Timer timer)

A timeout callback method can have public, private, protected, or package level access. It must not be declared as final or static. It must not throw application exceptions.

An EJB can have any number of automatically created timers.

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() {
   ...
}