Time spelling in automatic tasks

Source: Internet
Author: User

Quartz is a powerful enterprise-level task scheduling framework that inherits and simplifies quartz in spring, and looks at how to configure Quartz in spring: First we write a class that is dispatched:

1  Package Com.kay.quartz; 2  Public class Quartzjob 3 {45       Public void Work () 6      {7      System.out.println ("Quartz Task Scheduler!!! "); 8      }9  }

Spring's configuration file:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE Beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd ">3 4 <Beans>    5         <!--the work class to invoke -6         <BeanID= "Quartzjob"class= "Com.kay.quartz.QuartzJob"></Bean>7         <!--define methods for calling and invoking objects -8         <BeanID= "Jobtask"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">9             <!--the class that is called -Ten             < Propertyname= "TargetObject"> One                 <refBean= "Quartzjob"/> A             </ Property> -             <!--calling methods in a class - -             < Propertyname= "Targetmethod"> the                 <value>Work</value> -             </ Property> -         </Bean> -         <!--Define trigger Time - +         <BeanID= "Dotime"class= "Org.springframework.scheduling.quartz.CronTriggerBean"> -             < Propertyname= "Jobdetail"> +                 <refBean= "Jobtask"/> A             </ Property> at             <!--cron-expression - -             < Propertyname= "Cronexpression"> -                 <value>10,15,20,25,30,35,40,45,50,55 * * * *?</value> -             </ Property> -         </Bean> -         <!--General Management Class if you lazy-init= ' false ' then the container starts executing the scheduler - in         <BeanID= "Startquertz"Lazy-init= "false"Autowire= "No"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"> -             < Propertyname= "Triggers"> to                 <List> +                     <refBean= "Dotime"/> -                 </List> the             </ Property> *         </Bean> $     Panax Notoginseng </Beans>

Test procedure:

1  PackageCom.kay.quartz;2 3 ImportOrg.springframework.context.ApplicationContext;4 ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;5 6  Public classmaintest7  {8 9      /**Ten       * @paramargs One       */ A       Public Static voidMain (string[] args) -      { -System.out.println ("Test start.")); theApplicationContext context =NewClasspathxmlapplicationcontext ("Quartz-config.xml"); -          //if the Startquertz Bean's lazy-init is set to False in the configuration file, it will not be instantiated -         //Context.getbean ("Startquertz"); -System.out.print ("Test End:"); +           -  +      } A  at}

D.crontrigger configuration format: Format: [seconds] [min] [hours] [day] [month] [week] [year] The serial number description is required to fill the allowed value of the allowed wildcard character 1 seconds is 0-59,-*        /2 points is 0-59,-*/3 hours is 0-23,-*/4th is 1-31 , - * ? /L W May is 1-12 or JAN-DEC,-*/6 weeks is 1-7 or SUN-SAT,-*? /L # 7 years no empty or 1970-2099,-*/Wildcard Description: *: denotes all values. For example: Setting "*" on a divided field means that every minute is triggered. : Indicates that no value is specified. Use the scene as a value that does not need to be concerned with the current setting of this field. For example: to trigger an action at number 10th per month, but do not care about the week, so the field that needs the week position is set to "?" setting to 0 0 0 10 *?-: Indicates the interval. For example, setting "10-12" on the hour indicates that the 10,11,12 point will be triggered. ,: Indicates that multiple values are specified, such as setting "Mon,wed,fri" on the week field to indicate Monday, Wednesday, and Friday triggers/: Used to increment the trigger. If you set "5/15" above the second, the trigger (5,20,35,50) starts at 5 seconds, every 15 seconds. The month field is set to start at ' 1/3 ' as shown in month 1th and is triggered every three days. L: Indicates the last meaning. On the day field setting, the last day of the month (according to the current month, if February is also based on whether it is run year [leap]), the week field represents Saturday, which is equivalent to "7" or "SAT". If you precede the "L" with a number, it represents the last of the data. For example, setting the format "6L" On the week field means "last Friday of the month" W: Represents the most recent weekday from the specified date (Monday to Friday). For example, set "15W" on the day field, which indicates the most recent day of the month from 15th. If the number 15th is exactly Saturday, then find the most recent Friday (14th) trigger, if 15th is a week, then find the nearest next Monday (16th) to trigger. If the number 15th is exactlyOn weekdays (Monday to Friday), it is triggered on that day. If the specified format is "1W", it represents the next most recent weekday trigger of 1th per month. If the number 1th is Saturday, it will be triggered by the number 3rd in Monday. (Note that the "W" can only be set to a specific number before the interval "-") is not allowed. ' L ' and ' W ' can be used in a combination. If "LW" is set on the day field, then the last business day of the month is triggered #: ordinal (indicates the week of the month), for example, setting "6#3" on the week field represents the third week of the month in Saturday. Note If you specify "6#5", which is not Saturday for the fifth week, the configuration is not triggered (           For Mother's Day and Father's Day. The settings for the week field, if the English letter is case-insensitive Mon is the same as Mon. Common examples: Format: [seconds] [min] [hours] [day] [month] [week] [year] 0 0 12 * *? 12-point Trigger 0 15 10 per day?          * * Daily 10:15 Trigger 0 15 10 * *? Trigger 0 15 10 * * per day 10:15? * Daily 10:15 Trigger 0 15 10 * *?           2005 2005 Daily 10:15 Trigger 0 * 14 * *?         Every afternoon from 2 to 2:59 per minute trigger 0 0/5 14 * *?        Every afternoon from 2 to 2:59 (the whole point starts, every 5 minutes trigger) 0 0/5 14,18 * *?            Every afternoon from 18 to 18:59 (the whole point starts, every 5 minutes trigger) 0 0-5 14 * *? 0 10,44 14 per minute from 2 to 2:05 every afternoon? 3 WED March every Wednesday pm 2:10 and 2:44 trigger 0 15 10?            * Mon-fri from Monday to Friday every morning 10:15 trigger 0 15 10 15 *?             15th 10:15 A.M. per month, trigger 0 L *? 10:15 trigger on the last day of the month 0 15 10? * 6L of the last week of the month of Friday 10:15 trigger 0 15 10? * 6L 2002-2005 from 2002 to 2005 the last week of the month of Friday 10:15 trigger 0 15 10? * 6#3 The third week of the monthStart of Friday trigger 0 0 12 1/5 *?           The first noon of each month starts every 5 days and triggers 0 11 11 11 11?  November 11 11:11 Triggers (Singles Day) Note: The Simpletriggerbean class can only be used to specify the execution period between the simple job and the job, and if it needs to be performed at a specified time, the Crontriggerbean class may be used.

Time spelling in automatic tasks

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.