When spring sets a timed task, the rule setting for execution time

Source: Internet
Author: User
Tags time interval
Spring sets a timed task that may have the following configuration:

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" > <!-- Run timed tasks require jar package Quartz-all-1.6.5.jar, commons-collections-3.2.jar--> <beans> <!--A class of two timed tasks configure the target class you want to load periodically-- > <bean id= "autosmsjob" class= "Student.quartz.job.AutoSmsJob"/> <!--scheduled Task 1--> <bean id= "autosmsb2c Jobdetail "class=" Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean > <!--Specify the task class-- > <property name= "targetobject" ref= "Autosmsjob"/> <!--Specify task methods--> <property name= "Targetmethod" Value= "autosmsb2c"/> <property name= "concurrent" value= "false"/> </bean> <!--define time interval triggers--> &L T;bean id= "Autosmsb2cjobdetailcrontrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" > < Property name= "Jobdetail" > <ref bean= "autosmsb2cjobdetail"/> </property> <property name= "Cronexp"Ression "> &LT;VALUE&GT;*/5 * * * *?</value> </property> </bean> <!--start Timer--> <be An id= "ssschedulerfactory" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init= "false" > <property name= "triggers" > <list> <ref local= "Autosmsb2cjobdetailcrontrigger"/> < /list> </property> </bean> </beans>

As you can see from the configuration above, Org.springframework.scheduling.quartz.CronTriggerBean allows you to more accurately control the running time of a task, only to set its cronexpression properties.
A cronexpression expression has at least 6 (or possibly 7) time elements separated by a space. From left to right, these elements are defined as follows:
I. Description of each domain
Field fields Seconds Part When Day Month Week (7 for Saturday) Years (optional)
Take value range 0-59 0-59 0-23 1-31 1-12 or Jan–dec 1-7 or Sun–sat 1970–2099
Available characters , - * / , - * / , - * / , - * ? /L W C , - * / , - * ? /L C # , - * /
Sample Example 1 Example 2 Example 3 Example 4 Example 5 Example 6 Example 7

Ii. Illustrative examples
Example 1
: Perform once every 5 seconds: */5 * * * *?

Example 2: Perform once every 5 minutes: 0 */5 * * *?
In 26 points, 29 points, 33 minutes: 0 26,29,33 * * *?

Example 3: 12:30 P.M. every day: 0 30 0 * *? (Note that the date field is 0, not 24)
One 1 o'clock in the morning every day: 0 0 1 * *?
One 10:15 every day: 0 15 10? * * or 0 15 10 * *? or 0 15 10 * *? *
One 12 o'clock noon every day: 0 0 12 * *?
Daily from 14 o'clock to 14:59, every 1 minutes: 0 * 14 * *?
Daily from 14 o'clock to 14:05, every 1 minutes: 0 0-5 14 * *?
Daily from 14 o'clock to 14:55, every 5 minutes: 0 0/5 14 * *?
Every day from 14 o'clock to 14:55, and 18 to 18:55, every 5 minutes to execute: 0 0/5 14,18 * *?
0 0 18 * * For every day at 18 O ' time:
18-point, 22-point execution per day: 0 0 18,22 * *?
Every day from 7 o'clock to 23, every hour is executed: 0 0 7-23 * *?
Perform once per hour: 0 0 0/1 * *?

Example 4: 0 0 1 1 * 1th per month, 1 o'clock in the morning
0 15 10 15 * For every 15th-month-10:15 execution:
10:15 execution of the last day of the month: 0 L *?

Example 5: 23 on the last day of each month: 0 0 L *?

Example 6: Sunday 1 o'clock in the morning every week: 0 0 1? * L
March every Wednesday of 14:10 and 14:44 performed once: 0 10,44 14? 3 WED
Every Monday, Tuesday, Wednesday, Thursday, Friday 10:15 execution once: 0 15 10? * Mon-fri
10:15 of the last Friday of each month: 0 15 10? * 6L

Example 7: 2016 every day 10:15 to perform one time: 0 15 10 * *? 2016

Third, special character description
"," character
: Lists enumerated value values. For example: 0 26,29,33 * * * means to be executed at 26, 29, 33.

'-' character : Specifies the range of a value. For example: 0 0-5 14 * * * means every day from 2 o'clock in the afternoon to 2:05, every 1 minutes.

"*" character : indicates that any value that matches the field, if used in the Minutes field, means that the event is triggered every minute. For example: 0 * 14 * *? means every day starting from 2 o'clock in the afternoon to 2:59, every 1 minutes.

"/" character : Specifies the increment of a value. The n/m says to start with N, increment m every time. For example: */5 * * * * means to perform once every 5 seconds

"L" character : The last day of the one month in the day, used in the week to indicate the last one weeks of the week, that is, Sunday. For example: 0 0 L *? Represents the last day of each month at 23 o ' time.

"W" character : Specifies the most recent weekday from the given date (Monday to Friday). For example: Use 5W in the field month field, and if 5th is Saturday, it will be triggered on the most recent weekday: Friday, 4th. If 5th is Sunday, it is triggered on 6th (Monday) and if 5th is a day from Monday to Friday, it will be triggered on 5th. Another point, W's recent search will not span the month.

"LW" character : These two characters can be used to denote the last working day of a month, the last Friday.

"#" character : Represents the week X of the month. For example: 6#3 says the 3rd Friday of the Month

"?" Character : Represents an indeterminate value. Only used in the month and week two fields. It also matches any value of the field, but not actually. Because "month" and "Week" will affect each other. For example, in the month of 20th to trigger the schedule, no matter 20th is the day of the week, you can only use the following: 0 0 0 20 *?, the last one can only be used. , not using *, which is not the case if you use * to indicate whether the day of the week will trigger.

the "C" character : Available for the day and week fields, which is the abbreviation for calendar. It is represented as a value computed, if any, based on the relevant calendar. If there is no calendar associated with it, it is equivalent to including all calendars. The day field value of "5C" indicates "after the first or 5th numbers in the Calendar", and the "Week" field value "1C" means "the first day in the calendar or after Sunday."


 

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.