Quartz timing execution and time allocation

Source: Internet
Author: User

Quartz is a powerful enterprise-class Schedule tool and the best open source Schedule tool at the moment. The quartz application is also integrated into spring, so let's talk about using quartz in spring.

1, quartz need to add quartz-1.6.x.jar above the package

2. Spring needs to add Spring-context-support.jar package

The configuration of spring:

<bean id= "buildXML" class= "Com.targtime.statplat.schedule.QuartzXML" ></bean>

<bean id= "Buildxmldetail" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" ref= "buildXML" ></property>
<property name= "Targetmethod" value= "Execute"/>
<property name= "Concurrent" value= "true"/>
</bean>

<bean id= "Buildxmltrigger" class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean"
  <property name= "Jobdetail" ref= "Buildxmldetail"/>
  <property name= " Cronexpression "value=" 0 0 4 * *? />
 </bean>

<bean id= "Localquartzscheduler"
  class= " Org.springframework.scheduling.quartz.SchedulerFactoryBean
  <!--triggers integration;
  <property name= "triggers"
   <list>
       <ref bean= "Buildxmltrigger"/>
   </list>
  </property
  <!--quartz configuration;
  <property name= "quartzproperties"
    <props>
    <prop key= "Org.quartz.threadPool.threadCount" >5</ Prop>
   </props>
  </property>
  <!-- 3 seconds to start on task
  <property name= "Startupdelay" value= "3"/>
 </bean>

①targetmethod: Specifies that the Execute () method in buildXML must be executed periodically
②concurrent: For the same jobdetail, when multiple trigger are specified, it is likely that the second job will begin before the first job completes. Specifies that concurrent is set to false, multiple jobs will not run concurrently, and the second job will not start before the first job completes.
③CRONEXPRESSION:0/10 * * * * * * means to perform every 10 seconds, refer to the schedule.
④triggers: Multiple triggers can be placed in the list by adding additional ref elements.
The Execute () method in buildXML, noting that this method has no parameters and that if buildXML has two methods execute () and execute (String argument), spring will only execute the parameterless execute ().

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.

Schedule:
"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 * *" is triggered every 1 minutes from 2 o'clock in the afternoon to 2:59 every day
"0 0/5 14 * *" is triggered every 5 minutes from 2 o'clock in the afternoon to 2:55 every day
"0 0/5 14,18 * * *" triggered every 5 minutes from 2 o'clock in the afternoon to 2:55 and 6 o'clock in the afternoon to 6:55 every day
"0 0-5 14 * *" is triggered every 1 minutes from 2 o'clock in the afternoon to 2:05 every day
"0 10,44 14?" 3 WED "Every March of Wednesday, 2:10 and 2:44 triggers
"0 15 10?" * Mon-fri "from Monday to Friday 10:15 trigger
"0 15 10 15 *" Every month 15th 10:15 trigger
"0 L *?" triggered 10:15 the last day of every month
"0 15 10?" * 6L "last Friday 10:15 trigger per month
"0 15 10?" * 6L 2002-2005 "2002 to 2005 monthly last Friday 10:15 trigger
"0 15 10?" * 6#3 "The third Friday 10:15 trigger per month
As for each symbol, take a look at the example. It's easy.


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.