Quartz configuration Spring Timer Java timer in spring

Source: Internet
Author: User

Quartzjob.java


This program is placed in a Web project, after startup is loaded. 5 copies of the clock is automatically called once


[Java]View Plaincopyprint?
    1. Public class {
    2. Public void work () {
    3. System.out.println ("Quartz Task Scheduler!!!  ");
    4. Calendar cal=calendar.getinstance ();
    5. System.out.println (Cal.gettime ());
    6. }
    7. }

Spring configuration file

[HTML]View Plaincopyprint?
  1. <!--timed delivery --   
  2. <!--the work class to invoke--   
  3. < Bean id="quartzmsg" class=" Com.ppzhao.QuartzJob "></bean>
  4. <!--define methods for calling objects and calling objects--   
  5. < Bean id="msgjobtask"
  6. class = "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >   
  7. <!--called Class--   
  8. < Property name="targetObject">
  9. < ref bean="quartzmsg" />
  10. </ Property >   
  11. <!--calling methods in class--   
  12. < Property name="Targetmethod">
  13. < value > Work </ value >   
  14. </ Property >   
  15. </ Bean >   
  16. <!--define trigger time -   
  17. < Bean id="msgdotime" class=" Org.springframework.scheduling.quartz.CronTriggerBean ">
  18. < Property name="jobdetail">
  19. < ref bean="msgjobtask" />
  20. </ Property >   
  21. <!--cron Expressions--   
  22. < Property name="cronexpression">
  23. < value > 0 0/5 * * *? </ value >   
  24. </ Property >   
  25. </ Bean >   
[HTML]View Plaincopyprint?
  1. <!--general Management class if you lazy-init= ' false ' then the container starts executing the scheduler --   
  2. < Bean id="Startquertz" lazy-init="false" autowire="No"
  3. class = "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >   
  4. < Property name="triggers">
  5. < List >   
  6. < ref bean="msgdotime"/>
  7. </ List >   
  8. </ Property >   
  9. </ Bean >   


About cron expressions (from the network):

The Cron expression consists of the following 7 fields:

Seconds
Score of
Hours
Date within the month
Month
Week Date
Year (optional field)
Special characters

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.
Special characters allowed for field allowed values
Seconds 0-59,-*/
Sub 0-59,-*/
Hours 0-23,-*/
Date 1-31,-*? /L W C
Month 1-12 or JAN-DEC,-*/
Week 1-7 or Sun-sat,-*? /L C #
Year (optional) leave blank, 1970-2099,-*/
Meaning of an expression
"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
Every morning at 6.

0 6 * * *

Every two hours

0 */2 * * *
Every two hours between 11 o'clock and 8 in the morning, eight in the morning.

0 23-7/2,8 * * *

Every month, number 4th and Monday to Sunday, three a.m., 11.

0 11 4 * 1-3
January 1 morning, 4.

0 4 1 1 *

Quartz configuration Spring Timer Java timer in spring

Related Article

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.