Spring Multiple timed Tasks quartz configuration

Source: Internet
Author: User

Spring Multiple timed Tasks quartz configuration

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd "
Default-lazy-init= "false" >


<bean id= "Job1" class= "COM.JOB.JOB1"/>//Task 1
<bean id= "Job2" class= "COM.JOB.JOB2"/>//Task 2

<bean id= "Jobdetail_1"
   class= " Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean "
   <property name= "TargetObject"
    <ref bean= "Job1"/>
   </property>
    <property name= "Targetmethod"
    <value>jobmethod1</value>//method of execution
   </property>
</bean>
<bean id= "jobdetail_2"
   class= " Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean "
   <property name= "TargetObject"
    <ref bean= "Job2"/>
   </property>
    <property name= "Targetmethod"
    <value>jobmethod2</value>
    </PROPERTY>
</bean>

<bean id= "Crontrigger_1"
class= "Org.springframework.scheduling.quartz.CronTriggerBean" >
<property name= "Jobdetail" >
<ref bean= "Jobdetail_1"/>
</property>
<property name= "Cronexpression" >
<value>0 0 0 * * </value>//once a day 12 o'clock in the morning
</property>

</bean>
<bean id= "Crontrigger_2"
class= "Org.springframework.scheduling.quartz.CronTriggerBean" >
<property name= "Jobdetail" >
<ref bean= "Jobdetail_2"/>
</property>
<property name= "Cronexpression" >
<value>0 0 */1 * * * </value>//every hour
</property>
</bean>

<bean
class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref local= "crontrigger_1"/>
<ref local= "crontrigger_2"/>
</list>
</property>
</bean>

</beans>


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:
1. Seconds (0–59)

2. Minutes (0–59)

3. Hours (0–23)

4. Date in the month (1–31)

5. Month (1–12 or JAN–DEC)

6. Days of the week (1–7 or Sun–sat)

7. Year (1970–2099)

0 0 10,14,16 * *?

Daily 10 o'clock in the morning, 2 o'clock in the afternoon and 4 o'clock in the afternoon

0 0,15,30,45 * 1-10 *?

Every 15 minutes before 10 days per month

30 0 0 1 1? 2012

On January 1, 2012, 30 seconds after midnight.

0 0 8-5? * Mon-fri

Working hours per working day


The available values for each time are as follows:
Seconds 0-59,-*/

Cent 0-59,-*/

Hour 0-23,-*/

Day 1-31,--*? /L W C

Month 1-12 or JAN-DEC,-*/

Weeks 1-7 or Sun-sat,-*? /L C #

Year (optional field) empty, 1970-2099,-*/


The available values are analyzed in detail as follows:
"*"--characters can be used for all fields, and "*" in the "in" field means "every minute".

“?” --characters can be used in the days and weeks fields. It is used to specify the ' ambiguous value '. This is used when you need to specify one of the values in these two fields, not the other. In the following example, you can see what it means.

"-"--characters are used to specify a range of values, such as set to "10-12" in the "hour" field to indicate "10 to 12 points".

","--the character specifies a number of values. For example, in the "Weeks" field set to "Mon,wed,fri" means "The days Monday, Wednesday, and Friday."

"/"--characters are used to specify the increment of a value. For example, in the "Seconds" field set to "0/15" means "No. 0, 15, 30, and 45 seconds." and "5/15" means "5th, 20, 35, and 50". The '/' plus ' * ' character is equivalent to specifying starting from 0 seconds. Each field has a series of values that can start or end. For the seconds and minutes fields, the range is 0 to 59, 0 to 23 for the hour field, 0 to 31 for the day field, and 1 to 12 for the month field. The "/" field is only a value that helps you to start "nth" within the range of allowable values.

"L"--characters can be used in two fields, days and weeks. It is the abbreviation for "last", but there are different meanings in these two fields. For example, "L" in the "Day" field means "last day in one months"-for January is number 31st for February is 28th (not a leap year). In the weeks field, it simply means "7" or "SAT", but if used in the "Weeks" field after a number, it means "the last one weeks of the month X"-for example, "6L" means "the last Friday of the month". When using the ' L ' option, it is important to specify a list or range, otherwise you will be confused by the results.

"W"--Available for the day field. Use to specify the most recent weekday (Monday to Friday) for the given date of the calendar. For example, you set the "Day" field to "15W", meaning: "From the month of 15th, the most recent working day." So if number 15th is Saturday, the trigger will be called at number 14th, Friday. If number 15th is Sunday, the trigger will be triggered at number 16th, which is Monday. If the number 15th is Tuesday, then the day will be triggered. However, if you set the "Day" field to "1W" and the first number is Saturday, the trigger will be triggered in the next Monday, the month 3rd, because it will not cross the range boundary of the month's value. The ' W ' character can only be used when the value of the ' Day ' field is a single day instead of a series of values.

"L" and "W" can be combined for the "Day" field to be represented as ' LW ', meaning ' last weekday of the month '.

"#"--characters can be used in the weeks field. The character represents "Weeks X" of the month, such as "6#3", which represents the third Friday of the month (6 for Friday and "#3" for the third month). Another example: "2#1" = means the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" there is no fifth "week X" for the month, the month is not triggered.

"C"--characters can be used for the days and weeks fields, which are abbreviations 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."

The legal characters for the month and week fields are not case sensitive.


Some examples:
"0 0 12 * *" Every day 12 o'clock noon.

"0 15 10?" * * "Every 10:15 trigger

"0 15 10 * *" Every day 10:15 trigger

"0 15 10 * *? * "Every 10:15 trigger

"0 15 10 * *? 2005 "2005 Every day 10:15 triggers

"0 * 14 * *" Every day starting from 2 o'clock in the afternoon to 2:59 every minute of the trigger

"0 0/5 14 * *" Every day starting from 2 o'clock in the afternoon to 2:55 ending every 5 minutes

"0 0/5 14,18 * *" Every day from 2 o'clock in the afternoon to 2:55 and 6 to 6:55 for two time periods every 5 minutes to trigger

"0 0-5 14 * *" Every day from 14:00 to 14:05 per minute trigger

"0 10,44 14?" 3 WED "March of 14:10 and 14:44 triggers per Wednesday

"0 15 10?" * MON-FRI "10:15 triggers per Monday, Tuesday, Wednesday, Thursday, Friday

"0 15 10 15 *?" 15th trigger per month 10:15

"0 L *?" 10:15 trigger for the last day of the month

"0 15 10?" * 6L "Last month of Friday 10:15

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.