@javax.ejb.Schedule: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * EJB Annotations * Timer Service =Overview= Used for automatic timer creation.")
 
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://docs.oracle.com/javaee/7/api/javax/ejb/Schedule.html
=Internal=
=Internal=


* [[EJB_Annotations#Annotations|EJB Annotations]]
* [[EJB_Annotations#Annotations|EJB Annotations]]
* [[Timer Service]]
* [[EJB Timer Service]]


=Overview=
=Overview=


Used for [[EJB_Timer_Service#Automatic_Timer_Creation|automatic timer creation]].
Used by EJB to designate timeout callback methods that will be invoked by [[EJB_Timer_Service#Automatic_Timer_Creation|automatically-created timers]].
 
Example:
 
<syntaxhighlight lang='java'>
@Schedule(hour="3", dayOfMonth="1", info="something")
public void toBeExecutedAt3AMOnTheFirstDayOfTheMonth() {
  ...
}
</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=
 
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
 
<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
:<br>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.<br><br>
</blockquote>
 
The following example fires a timer every 20 seconds, continuously:
 
<syntaxhighlight lang='java'>
@Schedule(hour="*", minute="*", second = "0/20")
public void fireEvery20SecsContinously() {
  ...
}
</syntaxhighlight>

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