"Cronexpression expression and Case"

Source: Internet
Author: User

1. Cron-expression format:

{seconds} {minutes} {hours} {date} {month} {week} {year (nullable)}

2. The cron expression is interpreted by each placeholder:

{seconds} ==> allowed value range: 0~59, null value not allowed, if the value is not valid, the scheduler throws Schedulerexception exception

"*" represents a trigger every 1 seconds;

"," represents the triggering of a task at a specified number of seconds, such as "0,15,45" for 0 seconds, 15 seconds, and 45 seconds

"-" represents a trigger within a specified range, such as "25-45" for triggering from 25 seconds to 45 seconds, triggering 1 times every 1 seconds

"/" represents the trigger step (step), "/" The preceding value represents the initial value ("*" equals "0"), and the following value represents the offset, such as "0/20" or "*/20" for 0 seconds, every 20 seconds triggered 1 times, 0 seconds is triggered 1 times, 20 seconds is triggered 1 times, 40 seconds is triggered 1 times; 5/20 "for 5 seconds to trigger 1 times, 25 seconds to trigger 1 times, 45 seconds to trigger 1 times;" 10-45/20 "represents a point-in-time trigger with a 20-second hit in [10,45], 10 seconds triggering 1 times 30 seconds triggering 1 times

{minutes} ==> allowed value range: 0~59, null value not allowed, if the value is not valid, the scheduler will throw Schedulerexception exception

"*" represents a trigger every 1 minutes;

"," represents a trigger on a specified minute, such as "10,20,40" for 10 minutes, 20 minutes, and 40 minutes when the task is triggered

"-" represents a trigger within a specified range, such as "5-30" for triggering from 5 minutes to 30-minute end, every 1 minutes

The "/" represents the trigger step (step), the value preceding the "/" represents the initial value ("*" equals "0"), and the following value represents the offset, such as "0/25" or "*/25" for 0 minutes, every 25 minutes triggered 1 times, 0 minutes triggered 1 times, 25th minute triggered 1 times, 50th minute trigger 1 times, "5/25" for 5 minutes trigger 1 times, 30 minutes to trigger 1 times, 55 minutes to trigger 1 times, "10-45/20" for step 20 minutes in [10,45] hit point-in-time trigger, that is 10 minutes trigger 1 times, 30 minutes trigger 1 times

{hours} ==> allowed value range: 0~23, null value not allowed, if the value is not valid, the scheduler will throw Schedulerexception exception

"*" represents a trigger every 1 hours;

"," represents a trigger at a specified point in time, such as "10,20,23" to trigger a task at 10 o'clock, 20 o'clock, and 23.

"-" represents a trigger within a specified time period, such as "20-23" for triggering from 20 o'clock to 23 o'clock end trigger, every 1 hours

The "/" represents the trigger step (step), the value preceding "/" represents the initial value ("*" equals "0"), and the following value represents the offset, such as "0/1" or "*/1", which is triggered from 0 o'clock, 1 times every 1 hours, "1/2" is triggered from 1 o'clock, and every 2 hours thereafter; The "19-20/2" expression will be triggered only at 19 points

{Date} ==> allowed value range: 1~31, null value not allowed, if the value is not valid, the scheduler will throw Schedulerexception exception

"*" represents a daily trigger;

"?" is mutually exclusive with {week}, meaning that {week} is explicitly specified to trigger, which means {date} is meaningless to avoid conflicts and confusion

"," represents a trigger on a specified date, such as "1,10,20" for the 3-day period of 1th, 10th, and 20th

"-" represents a trigger within a specified date range, such as "10-15" for triggering from start 10th to end 15th, every 1 days

The "/" represents the trigger step (step), the value preceding "/" represents the initial value ("*" equals "1"), and the following value represents the offset, such as "1/5" or "*/5" for triggering from 1th, triggering 1 times every 5 days, "10/5" for triggering from 10th, and every 5 days thereafter; The "1-10/2" expression means that it is triggered every 2 days in the [1,10] range, that is, number 1th, number 3rd, 5th, 7th, number 9th.

"L" if the {date} placeholder is "L", which means that the last day of the month is triggered

"W" means that the most recent working day of the month is triggered, the so-called most recent working day, that is, that day to the shortest distance from the working day, if that day is a working day, the distance is 0; so-called this month, it is not possible to get to the nearest working day, even if the last day of the previous month/ Therefore, "LW" means that the last working day of this month is triggered, "W" strongly relies on {month}

"C" is triggered by the calendar and is not explained for the time being, due to less use

{Month} ==> allowed value range: 1~12 (JAN-DEC), NULL is not allowed, the scheduler throws a Schedulerexception exception if the value is not valid

"*" on behalf of each month is triggered;

"," represents a trigger in the specified month, such as "1,6,12" for January, June, and December trigger tasks

"-" represents a trigger within a specified month range, such as "1-6" for triggers starting from January to end of June, triggered every 1 months

The "/" represents the trigger step (step), the value preceding "/" represents the initial value ("*" equals "1"), and the following value represents the offset, such as "1/2" or "*/2", which is triggered starting from January, is triggered 1 times every 2 months, and "6/6" represents a trigger starting from June. Triggered once every 6 months; the "1-6/12" expression means that it triggers every January

{Week} ==> allowed value range: 1~7 (Sun-sat), 1 for Sunday (the first day of the week), and so on, 7 for Saturday (last day of the week), not allowed null value, if the value is not valid, The scheduler throws Schedulerexception exceptions

"*" represents a weekly trigger;

"?" is mutually exclusive with {date}, which means that {date} is explicitly specified to trigger, meaning {week} is meaningless to avoid conflict and confusion

"," represents a contract trigger on a specified week, such as "1,3,5" for Sunday, Tuesday, and Thursday triggers

"-" represents a trigger within a specified week range, such as "2-4" for triggers starting from Monday to end of Wednesday, triggered every 1 days

The "/" represents the trigger step (step), and the value preceding "/" represents the initial value ("*" equals "1"), and the following value represents the offset, such as "1/3" or "*/3", which is triggered starting from Sunday and is triggered 1 times every 3 days; "1-5/2" expression means that within [1,5] range, Triggered every 2 days, i.e. Sunday, Tuesday, Thursday

"L" If the {week} placeholder is "L", which means the last day of the week is triggered, that is, Saturday triggered, l= 7 or L = SAT, so "5L" means one months of the last Thursday trigger

"#" is used to specify the number of weeks, "#" in front of the week, "#" followed by the first few weeks of this month, such as "2#2" for the second week of this month in Monday, "5#3" represents the third week of the month of Thursday, so, "5L" This form is only "#" the special form of

"C" is triggered by the calendar and is not explained for the time being, due to less use

{year} ==> allowed value range: 1970~2099, allow null, if the value is not valid, the scheduler throws Schedulerexception exception

"*" represents a yearly trigger;

"," represents a trigger in a specified year, such as "2011,2012,2013" for 2011, 2012, and 2013 trigger tasks

"-" represents a trigger within a specified year range, such as "2011-2020" for triggers starting from 2011 to end of 2020, triggered every 1 years

The "/" represents the trigger step (step), the value preceding "/" represents the initial value ("*" equals "1970"), and the following value represents the offset, such as "2011/2" or "*/2" for triggering from 2011 onwards, triggering 1 times every 2 years

Note: You can use "?" except {date} and {week}. To implement mutual exclusion, and to express meaningless information, other placeholders have a specific time meaning, and the dependencies are: date (weeks), hours--

3. The powerful charm of cron expressions is the flexibility of horizontal and vertical combinations and simple syntax, with cron expressions that can write almost any point in time that you want to trigger

Classic case:

"30 * * * *?" triggers the task every half minute

"30 10 * * *?" 10 minutes and 30 seconds per hour trigger task

"30 10 1 * *?" 1 points per day 10 minutes 30 seconds trigger task

"30 10 1 20 *?" 20th 1, 10, 30 seconds per month. Trigger Task

"30 10 1 20 10?" * "Every October 20 1:10 30 seconds to trigger the task

"30 10 1 20 10?" 2011 "October 20, 2011 1:10 30 seconds Trigger Task

"30 10 1?" 10 * 2011 "October 2011 1 points per day 10 minutes 30 seconds trigger task

"30 10 1?" SUN 2011 "October 2011 every Sunday 1:10 30 seconds Trigger Task

"15,30,45 * * * *?" triggers the task every 15 seconds, 30 seconds, 45 seconds

"15-45 * * * *?" The task is triggered every second in 15-45 seconds

"15/5 * * * *?" starts firing every 15 seconds per minute, triggering every 5 seconds

"15-30/5 * * * *?" starts firing from 15 seconds to 30 seconds per minute, triggering every 5 seconds

"0 0/3 * * *?" starting at 0 minutes and 0 seconds per hour, triggering every three minute

"0 15 10?" * Mon-fri "Monday to Friday 10 points 15 minutes 0 seconds trigger task

"0 L *?" The last day of every month, 10 points, 15 minutes, 0 seconds. Trigger Task

"0 LW *?" 10 points in the last working day of each month 15 minutes 0 seconds trigger a task

"0 15 10?" * 5L "10 points per month for the last Thursday, 15 minutes, 0 seconds. Trigger a task

"0 15 10?" * 5#3 "The third week of the month of Thursday 10 points 15 minutes 0 seconds trigger a task

"Cronexpression expression and Case"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.