Java regular tasks (Cron Expressions Detailed)

Detailed cron expression

Cron expression is a string of 5 or 6 separated by a space, is divided into six or seven domains, each domain representing a meaning, Cron following two syntax:

Seconds Minutes Hours DayofMonth Month DayofWeek Year或
Seconds Minutes Hours DayofMonth Month DayofWeek

Each character field can appear as follows:
Seconds The: there may be "- * /" four characters, the valid range is an integer of 0-59
Minutes: there may be "- * /" four characters, the valid range is from 0 integer 59
Hours: there may be "- * /" four characters, valid integer in the range of 0-23
dayofMonth: there may be ", - * / LW C? " eight characters, valid integer in the range 0-31
Month: there may be "- * /" four characters, the effective range is an integer from 1 to 12 or DEC-JAN
DayofWeek: there may be "?, - * / LC # " four characters, the effective range of 1-7 SUN-SAT or an integer of two ranges. 1 for Sunday, 2 for Monday, and so on
Year: there may be "- * /" four characters, the effective range of 1970- 2099

Each domain using digital, but may also be present as a special character, their meanings are:
(1) : This field represents the value match any, if used in Minutes domain , i.e., represents a triggering event every minute.

(2) it can only be used ?: DayofMonth and DayofWeek two domains. It also matches any value of the field, but actually not. Because DayofMonth and DayofWeek affect each other. For example, want to trigger scheduled on the 20th of each month, regardless of the 20 in the end of the week, you can only use the following wording:? 13,131,520 *, which can only be the last one? , * Can not be used, no matter if you use * Indicates day of the week will be triggered, in fact not the case.

(3): - represents the range, for example 5-20 Minutes domain, represents from 5 per minute when the assigned time 20 minutes

(4) /: indicating a start time of a start trigger, and a trigger every predetermined time, for example 5/20 in Minutes domain, it means 5 minutes a trigger, and a trigger 25, 45, respectively.

(5) ,: listed represent the enumeration values. For example: the use of 5,20 in Minutes field, it means that the trigger once per minute at 5 and 20 minutes.

(6) L: represents the last, and only appeared in DayofWeek DayofMonth domain, if 5L in DayofWeek domain, meaning that triggered last Thursday.

(7) W: represents the effective working days (Monday to Friday), can only appear in DayofMonth domain, the system will trigger events in recent days from the effective date specified. For example: the use of 5W in DayofMonth, if the 5th is a Saturday, then in recent days: Friday that the 4th trigger. If the 5th is a Sunday, then on the 6th (Zhouyi) is triggered; if, in the Friday day, it triggers on Monday 5th in the 5th. Another point, W recently looking for does not cross the month

(8) LW: These two characters can be used in conjunction, it represents the last working day in a month, and last Friday.

(9) #: means for determining a month the first few days of the week, only appear in DayofMonth domain. For example, in 4 # 2, it represents the second Wednesday of the month.

A few examples:
? 0021 * * indicates the month 2:01 day scheduling tasks
0 15 10 * MON-FRI said on Monday through Friday at 10:15 am every day to perform the job?
0 15 10 6L? 2002-2006 represents 2002-- last Friday at 10:15 am for the implementation of the 2006 monthly

A cron expression of at least 6 (and possibly 7) has time elements separated by spaces.
According to the order to
seconds (0 to 59)
minutes (0 to 59)
hours (0 to 23)
days (month) (0 to 31, but you need to consider the number of days you months)
months (0 to 11)
days (week) (1 ~ 7 1 = SUN or SUN, MON, TUE, WED, THU, FRI, SAT)
Year (1970-2099)

Wherein each element can be a value (e.g., 6), a continuous section (9-12), a time interval (8-18 / 4) (/ indicates every 4 hours), a list (1,3,5) The wildcard. As the "day of the month" and "date of the week," these two elements are mutually exclusive, and must be for one of the settings?

00 10,14,16 * *? 10 am every day, 14:00, 4:00
0 0/30 * 9-17 *? Inward nine to five hours every half hour
0 0 12? * WED represent each Wednesday 12:00
"0012 * *?" 12:00 every day trigger
"01510? * *" at 10:15 am every day trigger
"01510 * *?" 10:15 am every day trigger
"01510 * *? * "at 10:15 am every day trigger
" 01510 * *? 2005 "2005 10:15 am every day trigger
" 0 * 14 * *? "1 period per day at 2:00 pm to 2:59 pm minute when the
"0 0/5 14 * *?" trigger every 5 minutes every afternoon 2:00 to 2:55 pm during the
"0 0/5 * 14, 18 *?" during the 2:00 to 2:55 every afternoon every five minutes and trigger 6:00 pm to 6:55 during the
"00-514 * *?" trigger per minute during the day at 2:00 pm to 2:05 pm
"0 10,44 14? 3 WED" Wednesday afternoon of March each year 2:10 and 2:44 trigger
"? 0 15 10 * MON- FRI" Monday to Friday 10:15 am to trigger
"0151015 *?" 15th of each month 10 am: 15 trigger
"0 15 10 L *?" on the last day of each month at 10:15 am triggering
"0 15 10? * 6L" most monthly 10:15 am Friday after a trigger
"0 15 10? * 6L 2002-2005 " 2002 years to 2005, the last Friday of each month at 10:15 am triggering
"01510? * 6 # 3" is the third Friday of each month at 10:15 am triggering

Some sub-expressions can contain a range or list

For example: subexpression (days (weeks)) can be "MON-FRI", "MON, WED, FRI", "MON-WED, SAT"

"*" Character represents all possible values

Thus, " " indicates the meaning of each month in the sub-expression (month), the " " in the sub-expression (days (weeks)) represent each day of the week

"/" Character is used to increment a specified value
, for example: in the subexpression (minutes) in the "0/15" starts from 0 minutes, every 15 minutes
in the sub-expression (minutes) in the "3/20 "starts from the first three minutes, every 20 minutes (and it" 3,23,43 ") as meaning

"?" Character is used only day (month) and day (week) two sub-expression that do not specify a value
when one of the two sub-expressions which are assigned a value in the future, in order to avoid conflict, you need to express another child style value is set to "?"

"L" character is used only day (month) and day (week) two sub-expressions, which is an abbreviation of the word "last" of
it meaning in the two sub-expressions is different.
Day (month) sub-expression, "L" represents the last day of the month
in the day (week) from the expression, "L" represents the last day of the week, which is the SAT

If there are specific content in the "L" before, it has other meanings of

For example: "6L" the reciprocal of the sixth day of the month, "FRIL" represents the best Friday of the month
Note: When using the "L" parameter, do not specify the list or range, as this can cause problems

Field allows values allow special characters
seconds 0-59, - * /
min 0-59, - * /
h 0-23, - * /
Date 1-31, -? * / LWC
March 1-12 or JAN-DEC, - * /
week 1-7 or SUN-SAT, -? * / LC #
years (optional) left blank, 1970-2099, - * /
crontab expressions generated online https://tool.lu/crontab/
reproduced to : https://www.cnblogs.com/linjiqin/p/3178452.html

Guess you like

Origin blog.csdn.net/LWHuai/article/details/86479275