-
@Target(value=METHOD) @Retention(value=RUNTIME) public @interface Schedule
Schedule a timer for automatic creation with a timeout schedule based on a cron-like time expression. The annotated method is used as the timeout callback method.All elements of this annotation are optional. If none are specified a persistent timer will be created with callbacks occuring every day at midnight in the default time zone associated with the container in which the application is executing.
There are seven elements that constitute a schedule specification which are listed below. In addition, the
timezone
element may be used to specify a non-default time zone in whose context the schedule specification is to be evaluated; thepersistent
element may be used to specify a non-persistent timer, and theinfo
element may be used to specify additional information that may be retrieved when the timer callback occurs.The elements that specify the calendar-based schedule itself are as follows:
- second : one or more seconds within a minute
Allowable values: [0,59]
- minute : one or more minutes within an hour
Allowable values : [0,59]
- hour : one or more hours within a day
Allowable values : [0,23]
- dayOfMonth : one or more days within a month
Allowable values:
- [1,31]
- [-7, -1]
- "Last"
- {"1st", "2nd", "3rd", "4th", "5th", "Last"} {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
"Last" means the last day of the month
-x (where x is in the range [-7, -1]) means x day(s) before the last day of the month
"1st","2nd", etc. applied to a day of the week identifies a single occurrence of that day within the month.
- month : one or more months within a year
Allowable values :
- [1,12]
- {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", Dec"}
- dayOfWeek : one or more days within a week
Allowable values :
- [0,7]
- {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
"0" and "7" both refer to Sunday
- year : a particular calendar year
Allowable values : a four-digit calendar year
Each element supports values expressed in one of the following forms
- Single Value. This constrains the attribute to only one of
its possible values.
Example: second = "10" Example: month = "Sep"
- Wild Card. "*" represents all allowable values for a given attribute.
Example: second = "*" Example: dayOfWeek = "*"
- List. This constrains the attribute to two or more allowable values
or ranges, with a comma used as a separator character within the string.
Each item in the list must be a single value or range. List items cannot
be lists, wild cards, or increments. Duplicate values are ignored.
Example: second = "10,20,30" Example: dayOfWeek = "Mon,Wed,Fri" Example: minute = "0-10,30,40"
- Range. This constrains the attribute to an inclusive range of values,
with a dash separating both ends of the range. Each side of the range
must be a single attribute value. Members of a range cannot be lists,
wild cards, ranges, or increments. If
x
is larger thany
in a range"x-y"
, the range is equivalent to"x-max, min-y"
, wheremax
is the largest value of the corresponding attribute andmin
is the smallest. The range"x-x"
, where both range values are the same, evaluates to the single valuex
. The day of the week range"0-7"
is equivalent to"*"
.Example: second = "1-10" Example: dayOfWeek = "Fri-Mon" Example: dayOfMonth = "27-3" (Equivalent to "27-Last , 1-3")
- Increments. The forward slash constrains an attribute based on a
starting point and an interval, and is used to specify every
N
seconds, minutes, or hours within the minute, hour, or day, respectively. For the expressionx/y
, the attribute is constrained to everyy
th value within the set of allowable values beginning at timex
. Thex
value is inclusive. The wild card character (*
) can be used in thex
position, and is equivalent to0
. The use of increments is only supported within thesecond
,minute
, andhour
elements. For thesecond
andminute
elements,x
andy
must each be in the range[0,59]
. For thehour
element,x
andy
must each be in the range[0,23]
.Example: minute = "∗/5" (Every five minutes within the hour)
This is equivalent to:minute = "0,5,10,15,20,25,30,35,40,45,50,55"
Example: second = "30/10" (Every 10 seconds within the minute, starting at second 30)
This is equivalent to:second = "30,40,50"
Note that the set of matching increment values stops once the maximum value for that attribute is exceeded. It does not "roll over" past the boundary.
Example : ( minute = "∗/14", hour="1,2")
This is equivalent to:
(minute = "0,14,28,42,56", hour = "1,2")
(Every 14 minutes within the hour, for the hours of 1 and 2 a.m.)
The following additional rules apply to the schedule specification elements:
- If the
dayOfMonth
element has a non-wildcard value and thedayOfWeek
element has a non-wildcard value, then any day matching either thedayOfMonth
value or thedayOfWeek
value will be considered to apply. - Whitespace is ignored, except for string constants and numeric values.
- All string constants (e.g.,
"Sun"
,"Jan"
,"1st"
, etc.) are case insensitive.
Schedule-based timer times are evaluated in the context of the default time zone associated with the container in which the application is executing. A schedule-based timer may optionally override this default and associate itself with a specific time zone. If the schedule-based timer is associated with a specific time zone, all its times are evaluated in the context of that time zone, regardless of the default time zone in which the container is executing.
The timeout callback method to which the
Schedule
annotation is applied must have one of the following signatures, where<METHOD>
designates the method name:void <METHOD>() void <METHOD>(Timer timer)
A timeout callback method can have public, private, protected, or package level access. A timeout callback method must not be declared as final or static. Timeout callback methods must not throw application exceptions.- Since:
- EJB 3.1
- second : one or more seconds within a minute
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element and Description String
dayOfMonth
Specifies one or more days within a month.String
dayOfWeek
Specifies one or more days within a week.String
hour
Specifies one or more hours within a day.String
info
Specifies an information string that is associated with the timerString
minute
Specifies one or more minutes with an hour.String
month
Specifies one or more months within a year.boolean
persistent
Specifies whether the timer that is created is persistent.String
second
Specifies one or more seconds with in a minute.String
timezone
Specifies the time zone within which the schedule is evaluated.String
year
Specifies one or more years.
-
-
-
Element Detail
-
second
public abstract String second
Specifies one or more seconds with in a minute.- Default:
- "0"
-
-
-
minute
public abstract String minute
Specifies one or more minutes with an hour.- Default:
- "0"
-
-
-
hour
public abstract String hour
Specifies one or more hours within a day.- Default:
- "0"
-
-
-
dayOfMonth
public abstract String dayOfMonth
Specifies one or more days within a month.- Default:
- "*"
-
-
-
month
public abstract String month
Specifies one or more months within a year.- Default:
- "*"
-
-
-
dayOfWeek
public abstract String dayOfWeek
Specifies one or more days within a week.- Default:
- "*"
-
-
-
year
public abstract String year
Specifies one or more years.- Default:
- "*"
-
-
-
timezone
public abstract String timezone
Specifies the time zone within which the schedule is evaluated. Time zones are specified as an ID string. The set of required time zone IDs is defined by the Zone Name(TZ) column of the public domain zoneinfo database.If a timezone is not specified, the schedule is evaluated in the context of the default timezone associated with the contianer in which the application is executing.
- Default:
- ""
-
-
-
info
public abstract String info
Specifies an information string that is associated with the timer- Default:
- ""
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/ejb/schedule.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.