Cronexpression Configuration instructions for task scheduling in spring

Source: Internet
Author: User

cron Expression Reprint address: http: // www.cnblogs.com/chinafine/articles/1773389.html Quartz uses a cron expression similar to Linux to define a time rule, and the Cron expression consists of 6 or 7 space-delimited time fields, as shown in table 1: Table 1 Cron expression Time field

Position

Time Domain

Allowed values

Allowed special characters

1

Seconds

0-59

, - * /

2

Minutes

0-59

, - * /

3

Hours

0-23

, - * /

4

Date

1-31

, - * ? /L W C

5

Month

1-12

, - * /

6

Week

1-7

, - * ? /L C #

7

Year (optional)

Null value 1970-2099

, - * /

the Time field of a cron expression, in addition to allowing you to set a value, can also use some special characters, such as lists, scopes, wildcards, and so on, as follows: asterisk (*): Available in all fields, representing every moment of the corresponding time domain, for example, *in the Minute field, represents "every minute"; Question mark (?): This character is used only in date and week fields, and it is usually specified as "meaningless value", which is equivalent to a dot character; a minus sign (-): Express a range, such as in the hour field using theTen- A", that means 10 to 12 points, or 10, One, A, comma (,): Represents a list value, such as using "Mon,wed,fri" in the Week field, which is Monday, Wednesday, and Friday; Slash (/): The X/y expression is an equal step sequence, the value is start, and Y is the increment step value. As in the Minutes field, use 0/ the, it is represented as 0, the, 30 and 45 seconds,
And 5/15 in the minute field represents 5, -, *, -, you can also use */y, which is equivalent to 0/y; L: This character is used only in the date and weekday fields, meaning "last", but it has a different meaning in two fields. L In the Date field, which represents the last day of the month,
For example, number 31st in January, 28th for non-leap year February, if L is used in the week, Saturday, equivalent to 7. However, if L appears in the Week field and there is a value x in front of it,
means "Last x days of the Month", for example, 6L represents the last Friday of the month; W: The character can only appear in a Date field, is a decoration on a leading date, and represents the most recent working day from that date. For example, 15W indicates the most recent working day from 15th of that month,
If the number 15th is Saturday, match 14th Friday; if 15th is Sunday, match 16th Monday; If number 15th is Tuesday, the result is 15th Tuesday.
But it must be noted that the associated match date is not able to cross the month, if you specify 1W, if 1th is Saturday, the result matches 3rd Monday, not the last day of last month.
The W string can only specify a single date and cannot specify a date range; LW combination: LW can be combined in a date field, which means the last working day of the month; pound sign (#): This character can only be used in the day of the week, indicating a weekday of the month. If 6#3 represents the third Friday of the month (6 means Friday, #3表示当前的第三个),
While 4#5 represents the fifth Wednesday of the month, assuming that the month does not have fifth Wednesday, ignored does not trigger; C: The character is used only in the date and week fields, meaning "Calendar". It means the date that the schedule is associated with, and if the date is not associated,
is equivalent to all dates in the calendar. For example 5C in a Date field is equivalent to the first day of the calendar after 5th. 1C is equivalent to the first day of Sunday after the week field. Cron expressions are insensitive to the case of special characters, and are not sensitive to the case of the abbreviated English-language representation of the week. Table 2 shows some examples of the complete cron expression:

Expression

Description

"0 0 12 * *?"

Runs at 12 o ' Day

"0 15 10?" * *"

Run 10:15 Daily

"0 15 10 * *?"

Run 10:15 Daily

"0 15 10 * *?" *"

Run 10:15 Daily

"0 15 10 * *?" 2008 "

Runs 10:15 every day in 2008.

"0 * 14 * *?"

It runs every minute from 14 o'clock to 15, starts at 14:00 and ends at 14:59.

"0 0/5 14 * *?"

Run every 5 minutes from 14 o'clock to 15 every day, starting at 14:00 and ending at 14:55.

"0 0/5 14,18 * *?"

It runs every 5 minutes from 14 o'clock to 15 every day, and also runs every 5 minutes from 18 o'clock to 19.

"0 0-5 14 * *?"

It runs every minute from 14:00 to 14:05.

"0 10,44 14?" 3 WED "

March every Wednesday from 14:10 minutes to 14:44, run every minute.

"0 15 10?" * Mon-fri "

Every Monday, two, three, four, five of 10:15 minutes run.

"0 15 10 15 *?"

Run every 15th 10:15.

"0 L *?"

Run 10:15 on the last day of each month.

"0 15 10?" * 6L "

Run the last month of Friday 10:15.

"0 15 10?" * 6L 2007-2009 "

Run 10:15 minutes in the last Friday of the month of the 2007,2008,2009 year.

"0 15 10?" * 6#3 "

Run for the third Friday month of 10:15 minutes.

Cronexpression Configuration instructions for task scheduling in spring

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.