The Cron Trigger is a more powerful time-based trigger than the Time Trigger. It allows to set up a Crontab like expression to trigger the task repeatedly.
The Cron Trigger uses the QUARTZ
syntax without seconds in the following form:
<minute> <hour> <dayOfMonth> <month> <dayOfWeek> <year>
*
for every minute*
for every hour*
for every day of the month and ?
if omittedL
stands for the last day of the monthW
stands for a day from Monday to Friday in the week*
for every month*
for every day of the week and ?
if omitted, L
stands for last day of the week
Note that one of the values <dayOfMonth>
and <dayOfWeek>
has to be ?
since they otherwise contradict each other. The <year>
value can be omitted. An Asterisk (*
) can be used for every value to specify all the possible values. Value ranges (e.g. 1-5), lists (e.g. JAN,FEB,MAR) and increments (e.g. 0/15 for 0, 15, 30, 45) are also allowed.
The documentation at Quartz Cron Tutorial has many details on how to create an expression.
0 8 * * ?
- every day at 8:00 am.0 8 15,20 JAN ?
- On 15th and 20th of January at 8:00am.30 18 ? 4,5,6 6#1
- On the first Friday at 6:30pm in April, May and June.
Monthly repeated tasks for days that do not exist will not be executed in that month. Example: 0 0 8 31 * ?
would execute the task on the 31st day of only January, March, May, July, August, October, and December. Instead, if you want to execute the task on the last day of each month, use the syntax "L" for last day: 0 0 8 L * ?
Tasks repeated on Monday to Friday will be executed by mistake on Saturday if the Friday is the last workday of the month.
See https://github.com/jmrozanec/cron-utils/issues for for more information.