Quartz.net Summary (ii) Crontrigger and cron expressions

Source: Internet
Author: User

Quartz.net's task scheduling, mainly relies on crontrigger and cron expressions. Cron is already in Unix for a long time, it has a strong and reliable scheduling ability. The Crontrigger class is also based on cron scheduling capabilities.

Crontrigger uses cron expressions. It can flexibly set up a variety of planning tasks, such as every Monday to Friday, 8 in the morning to perform a task. However, although Cron expressions are powerful and flexible, they are confusing and difficult to understand. So here's a description of the CRON expression-related configuration. I hope you will help us to understand quickly.

Cron format

Cron expressions are used to configure Crontrigger instances. A cron expression is a string consisting of 6, 7 fields (sub-expressions), and spaces. Each sub-expression describes a separate schedule detail
    domain    
    Force    
    allowable value    
    Allow special characters    
Seconds
YES
0-59
, - * /
Minutes
YES
0-59
, - * /
Hours
YES
0-23
, - * /
Day of month
YES
1-31
, - * ? /L W
Month
YES
1-12 or Jan-dec
, - * /
Day of week
YES
1-7 or Sun-sat
, - * ? L
Year
NO
Empty, 1970-2099
, - * /
So, like a cron expression string "0 0 10?" * MON ", which means" 12:00 noon every Monday ".

In the list above, it is clear that all the values in the domain have a specific legal scope, and each domain can be configured separately. For example: Day of week (days of the week) must have a value (SUN-SAT) or use special characters, so "0 0 * MON" can be changed to "Mon-fri", "Mon, WED, FRI" even "Mon-wed,sat".
Special Character description

' * ' indicates "each" in the domain. For example, the * in the "Minutes" field indicates every minute.

'? ' in the Day-of-month and Day-of-week fields, indicating "no value specified". This is useful when you need to specify a value for one or two fields without having to set up other domains. For example, I want to be on a day of one months (for example, the tenth), instead of the specific day, I will put "10" in the Day-of-month domain, then "? "In the Day-of-week."

'-' specifies the range, for example, "10-12" in the Hours field, which represents 10 to 12 points.

', ' specifies added value, for example, "Mon,wed,fri" in the Day-of-week field, which means "Monday, Wednesday, and Friday".

'/' does not have a specific value, used to specify the increment of the value, for example, if in the seconds field, ' 0/15 ', it means "starting from 0, every 15 seconds."

' L ' is used only in Day-of-month and Day-of-week, which is a shorthand for "last", but has a different meaning in two domains. For example, the "L" in the Day-of-month field represents the last day of the month, that is, 31st of January, non-leap year February of 28th. If it is used in day-of-week, it means "7" or "SAT". However, this character follows a different value, which means "last week of the month XXX". For example: "6L" or "Fril" represents the last Friday of this month. It can also be used to specify the penultimate day of the last day of the first month, such as "L-3", which indicates the last day of the month. Note: When using the ' L ' option, the most important thing is not to specify a list or range of values, which can cause confusion.

' W ' is used for the most recent day in the Day-of-week domain for a given day (Monday Friday). For example, "15W" means "the most recent working day from month 15th is the week".

' # ' represents the first few weeks of the month. For example: "6#3" or "fri#3" in the Day-of-week field means "third Friday of the month".

Related examples

An expression
Meaning
0 0 12 * *?
12 o'clock noon every day.
0 15 10? * *
Daily 10 o'clock in the morning 15
0 15 10 * *?
Daily 10 o'clock in the morning 15
0 15 10 * *? *
Daily 10 o'clock in the morning 15
0 * 14 * *?
Every day from 2 o'clock in the afternoon to 2 O ' 59 per minute
0 0/5 14 * *?
Every 5 minutes from 2 o'clock in the afternoon to 2 59 every day.
0 0/5 14,18 * *?
Every 55 minutes from 2 o'clock in the afternoon to 2, 59 and 6 to 6 5 every day.
0 0-5 14 * *?
Every day from 2 o'clock in the afternoon to 2 O ' 05 per minute
0 10,44 14? 3 WED
March every Wednesday 2 o'clock in the afternoon 10 and 2 point 44
0 15 10? * Mon-fri
Every Wednesday to Friday 10 o'clock in the morning 15
0 15 10 15 *?
10 o'clock in the morning 15 on the 15th day of every month
0 L *?
10 o'clock in the morning 15 on the last day of each month
0 L-2 *?
The last day of the month, the penultimate day of the next 10 o'clock in the morning 15
0 15 10? * 6L
Last Friday of the month 10 o'clock in the morning 15
0 15 10? * 6L 2002-2005
2002 to 2005 of the last of the monthly Friday 10 o'clock in the morning 15
0 15 10? * 6#3
The third Friday of every month. 10 o'clock in the morning 15
0 0 12 1/5 *?
Starting on the first day of every month, 12 o'clock noon every 5 days
0 11 11 11 11?
Every November 11, 11:11
Note: '? ' and ' * ' influence in Day-of-week and Day-of-month

Reference Link: http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontrigger.html

Quartz.net Summary (ii) Crontrigger and cron expressions

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.