Cron expression Guide

Source: Internet
Author: User

Cron Expressions--CronExpression

CronThe expression is used to configure the CronTrigger instance. A Cron expression is a string consisting of seven subexpressions. Each subexpression describes a separate schedule. These subexpressions are separated by spaces, indicating:

 

1. Seconds

2. Minutes

3. Hours hour

4. Days in Day-of-Month

5. Month

6. Day-of-Week Day of Week

7. Year (optional field)

The example string of a cron expression is"0 0 12? * WED", Which indicates "noon every Wednesday ".

A single subexpression can contain a range or a list. For example, the day field (here "WED") in the week in the previous example can be replaced with "MON-FRI", "MON, WED, FRI" or even "MON-WED, SAT ".

Wildcard ('*') can be used to indicate the possible values of "each" in the domain. Therefore, * in the "Month" field indicates each Month, and * in the Day-Of-Week field indicates "every Day Of the Week ".

Values in all fields have a specific valid range. The valid range of these values is quite obvious. For example, valid values of seconds and domain shards are 0 to 59, the valid range of hours is 0 to 23, and the value of Day-of-Month must be 0 to 31. However, you must note that the days in different months are different. The valid values of a month are 0 to 11. It can also be represented by the string JAN, feb mar, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, and DEC. Days-of-Week can be expressed by 1 to 7 (1 = Sunday) or SUN, MON, TUE, WED, THU, FRI, and SAT.

The '/' character is used to represent the increment of the value. For example, if the minute domain is put into '123', it indicates "every 15 minutes, starting from 0 ", if '20140901' is used in the intermediate domain, it indicates "every 20 minutes in the hour, starting from 3/20 minutes" or the same format is '3, 3rd '.

'? The 'character can be used in the day-of-month and day-of-week fields to indicate "no value specified ". This is useful when you need to specify the value of one or two domains without setting other domains. The following example (and CronTrigger JavaDOC) will be clearer.

The 'l' character can be used in day-of-month and day-of-week. This character is short for "last", but has different meanings in the two fields. For example, "L" in the day-of-month field indicates the last day of the month, that is, the 31st day of January 1, January, rather than the 28th day of January 1, February of a leap year. If it is used in day-of-week, it indicates "7" or "SAT ". However, if the character in the day-of-week field is followed by another value, it indicates "XXX of the last week of the month ". For example, "6L" or "FRIL" indicates the last Friday of this month. When you use the 'l' option, do not specify the list or value range. Otherwise, confusion may occur.

The 'W' character is used to specify the week closest to the specified day (in the day-of-week domain ). For example, if you specify "15 W" for the day-of-month field, it indicates the number of weeks closest to the 15th day of the month ".

'#' Indicates the number of weeks in a month. For example, "6 #3" or "FRI #3" in the day-of-week field indicates "the third Friday of the month ".

 

 

 

The following are some expressions and their meanings. You can find more examples in the JavaDOC of CronTrigger.

 

Example CronExpressions--CronExpression example

CronTrigger Example 1-a simple expression that is triggered every 5 minutes

"0 0/5 ***? "CronTrigger Example 2-expression that is triggered every five minutes after 10 seconds every minute (for example, 10:00:10 am, 10:05:10, etc .).

"10 0/5 ***? "CronTrigger Example 3-expression triggered at, and on every Wednesday and Friday.

"0 30 10-13? * WED, FRI "CronTrigger Example 4-triggered every 30 hours between and on the 5th, 20th, but not, 9: 00 and 9: 30 expressions.

"0 0/30 8-9 5, 20 *? "NOTE: For a single trigger, some schedule requirements may be too complex and cannot be expressed by expressions. For example, a trigger is triggered every five minutes between and, triggered every 20 minutes from PM to PM. This solution is to create two triggers, both of which run the same task.

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.