Quartz timing execution and time configuration

Source: Internet
Author: User

Quartz is a powerful enterprise-class Schedule tool and the best open source Schedule tool available today. The quartz application is also integrated in spring, so let's talk about how to use quartz in spring.

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

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

Spring Configuration:

<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 integrated-->
  <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-second delay on start task-->
  <property name= "Startupdelay" value= "3"/>
 </bean>

①targetmethod: Specifies that the Execute () method in buildXML needs to be timed
②concurrent: For the same jobdetail, when more than one trigger is specified, it is likely that the second job will begin before the first job is completed. Specifying concurrent is set to false, multiple jobs do not run concurrently, and the second job will not start until the first job is completed.
③CRONEXPRESSION:0/10 * * * * For every 10 seconds, refer to the schedule.
④triggers: You can place multiple triggers in the list by adding additional ref elements.
The Execute () method in buildXML, note: This method has no parameters, and 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,-*/

Sub 0-59,-*/

Hours 0-23,-*/

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

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

How many weeks 1-7 or SUN-SAT,-*? /L C #

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

The available values are analyzed in detail below:

"*"--the character can be used for all fields, and set to "*" in the "points" field means "every minute".

“?” --characters can be used in the "Day" and "Week" fields. It is used to specify ' ambiguous values '. This is used when you need to specify one of these two fields instead of the other. In the following example, you can see its meaning.

"-"--the character is used to specify a range of values, such as "10-12" in the "Hour" field for "10 point to 12 points".

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

"/"--the character is used to specify the increment of a value. For example, the "Seconds" field is set to "0/15" for "No. 0, 15, 30, and 45 seconds". "5/15" means "5th, 20, 35, and 50". The "*" character in front of '/' is equivalent to the specified starting at 0 seconds. Each field has a series of values that can start or end. For the seconds and minutes fields, the values range from 0 to 59, which is 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 simply a value that helps you to start "nth" within the allowable numeric range.

"L"--characters can be used in both "Day" and "Week" fields. It is the abbreviation for "last", but it has different meanings in both fields. For example, "L" in the day field means "the last day of one months"-for January is number 31st for February is 28th (not a leap year). In the "Weeks" field, it simply represents "7" or "SAT", but if it is followed by a number in the "Weeks" field, it means "the last one weeks of the month X"-such as "6L" for "The last Friday of the month". When using the ' L ' option, it is important to specify the list or scope of the determination, otherwise you will be confused by the result.

"W"--Available for the "Day" field. Used 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: "The most recent working day from the month of 15th." So if number 15th is Saturday, the trigger will be called at 14th, or Friday. If number 15th is Sunday, the trigger will be triggered at 16th, or Monday. If number 15th is Tuesday, it will be triggered the same day. However, if you set the "Day" field to "1W" and the number is Saturday, the trigger will be triggered in the next Monday, which is the 3rd number of the month, because it will not cross the range boundary of the value of the month. The ' W ' character can only be used when the value of the day field is a single day instead of a series of values.

The "L" and "W" can be combined for the "day" field expressed as ' LW ', meaning "the last working day of the month".

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

The "C"--character can be used for the "Day" and "Week" fields, which is the abbreviation for "Calendar". It represents the value, if any, that is computed based on the associated calendar. If there is no associated calendar, it is equivalent to including all calendars. The day field value of 5C means "the first day of the calendar or after 5th," and the "Weeks" field value "1C" means "the first day of the calendar or after Sunday."

Valid characters are not case-sensitive for the month field and the weeks field.

Schedule:
"0 0 12 * *?" trigger 12 o'clock noon every day.
"0 15 10?" * * "trigger 10:15 every day"
"0 15 10 * *?" Daily 10:15 Trigger
"0 15 10 * *?" * "10:15 per day" trigger
"0 15 10 * *?" 2005 "2005-year daily 10:15 Trigger
"0 * 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:59 daily
"0 0/5 14 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily
"0 0/5 14,18 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily and from 6 o'clock in the afternoon to 6:55
"0 0-5 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:05 daily
"0 10,44 14?" 3 WED "2:10 and 2:44 triggers in Wednesday of every March
"0 15 10?" * Mon-fri "Monday to Friday 10:15 trigger
"0 15 10 15 *?" 15th 10:15 per month
"0 L *?" 10:15 on the last day of the month
"0 15 10?" * 6L "Last month of Friday 10:15 Trigger
"0 15 10?" * 6L 2002-2005 "2002 to 2005 the last of the monthly Friday 10:15 trigger
"0 15 10?" * 6#3 "Monthly third Friday 10:15 trigger
Just look at the examples for each symbol. It's very simple.


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.