Spring's timed task cron expression

Source: Internet
Author: User

What cron expressions Are: First Cron is a scheduled task, that is, a cron expression is typically used to configure the trigger time for a scheduled task. A cron expression is a string consisting of six or seven sub-expressions (fields). sub-expressions, or fields, are separated by Spaces.
Field name is required allowable Values allowed special characters
Seconds (seconds) Y 0-59 , - * /
Points (minutes) Y 0-59 , - * /
Time (hours) Y 0-23 , - * /
Days (day of Month) Y 1-31 ,-*/L W C
Monthly (month) Y 0-11 or Jan-dec , - * /
Week (day of Week) Y 1-7 or Sun-sat , - * /? L C #
Years (year) N 1970-2099 or do not write , - * /

At this point, you can understand the previous six or seven sub-expressions or the meaning of the field, from the first to the last one to indicate the second time of day of the month of the last year of the week can not Write.

Cron triggers take advantage of a series of special characters, as Follows:

The backslash (/) character represents the increment Value. For example, in the seconds field, "5/15" represents the beginning of the 5th second, once every 15 seconds.

The question mark (?) character and the letter L character are available only in the date and week date fields within the Month. A question mark indicates that the field does not contain a specific Value. therefore, If you specify a date within a month, you can insert "?" in the Date field within the week, which means that the date value in the week does not matter.

The letter L character is the last Abbreviation. Placed in the month date field, indicates that the schedule is scheduled to be executed on the last day of the Month. In the week date field, if "L" exists alone, it is equal to "7", otherwise it represents the last instance of the week date within the Month. So "0L" means that it is scheduled to be executed on the last Sunday of the Month.

The letter (W) character in the Date field in the month arranges the execution at the working day closest to the specified Value. Placing "1W" in the Month Date field indicates that the execution is scheduled for the first business day of the Month.

The pound sign (#) character specifies a specific weekday instance for a given month. Put "mon#2" in the week date field, indicating that the task is scheduled for the second Monday of the Month.

The asterisk (*) character is a wildcard character that indicates that the field can accept any possible Value.

The following are detailed in the Example:

An expression Time of expression
0 0 12 * *? 12 O'Clock Noon every Day.
0 15 10? * * Daily 10:15 A.M.
0 15 10 * *? Daily 10:15 A.M.
0 15 10 * *? * Daily 10:15 A.M.
0 15 10 * *? 2005 Every day in 2005, 10:15 A.M.
0 * 14 * *? Every day from 14 o'clock in the afternoon to 14:59 to end such a time period
0 0/5 14 * *? Triggers every 5 minutes from 14 o'clock in the afternoon to 14:55 daily
0 0/5 14,18 * *? Triggers every 5 minutes from 14 o'clock in the afternoon to 14:55 and 18 to 18:55 every day.
0 0-5 14 * *? Every day from 14 o'clock in the afternoon to 14, 05 ENDS.
0 10,44 14? 3 WED Each March, every Wednesday, 14:10 P.M. and 14, 44.
0 15 10? * Mon-fri 10:15 on each weekday
0 15 10 15 *? Every month, 15th, 10:15 A.M..
0 L *? 10:15 on the last day of each month
0 15 10? * 6L Last Friday of every month 10:15
0 15 10? * 6L 2002-2005 2002 to 2005 each month the last Friday 10:15
0 15 10? * 6#3 The third Friday of every month 10:15
0 0 12 1/5 *? Every month starting from day one, every 5 days, 12 o'clock Noon.
0 11 11 11 11? Every November 11 11:11

0 6 * * * Every morning at 6.
0 */2 * * * Every two hours
0 23-7/2,8 * * * Every two hours between 11 o'clock and 8 in the morning, eight in the Morning.
0 11 4 * 1-3 Every month, number 4th and Monday to sunday, three a.m., 11.
0 4 1 1 * January 1 morning, 4.
examples are as follows:

/*** Regular Scheduled Tasks*/@Component ("timingtask") public classBss_soa_jobcontroller {@AutowiredPrivateBss_soa_baseservice Baseservice =NULL; // daily 23:55 insert tomorrow Data@Scheduled (cron = "0 55 23?") * *") public voidaddtomrrowdata () {baseservice.adddaliydata (); } //If you do not submit data to the system 5 days before 10 o ' day, The push is triggered every day 10:15@Scheduled (cron = "0 15 10?") * *" ) public voidTimer () {}}

Spring's timed task cron expression

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.