Configuration of Spring Base quartz

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: Package Com.kay.quartz;public Class quartzjob{public void work () {System.out.println ("Quartz Task Scheduler!!!    "); Configuration file for}}spring:<?xml version= "1.0" encoding= "UTF-8"?><! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" ><beans>            <!--the work class to invoke--        <bean id="Quartzjob" class="Com.kay.quartz.QuartzJob"> </Bean>        <!--define methods for calling objects and calling objects--        <bean id= "jobtask" class=" Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean ">            <!--called Class--            < property name="TargetObject">                <ref Bean="Quartzjob"/>            </Property >            <!--calling methods in class--            < property name="Targetmethod">                <value>Work</value>            </Property >        </Bean>        <!--define trigger time -        <bean id= "dotime" class=" Org.springframework.scheduling.quartz.CronTriggerBean ">            < property name="Jobdetail">                <ref Bean="Jobtask"/>            </Property >            <!--cron Expressions--            < property name="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 --        <bean id="Startquertz" lazy-init="false" Autowire ="No" class="Org.springframework.scheduling.quartz.SchedulerFactoryBean" >            < property name="triggers">                <list>                    <ref Bean="Dotime"/>                </list>            </Property >        </Bean></Beans>Test procedure: Package Com.kay.quartz;import Org.springframework.context.applicationcontext;import    Org.springframework.context.support.classpathxmlapplicationcontext;public class maintest{/** * @param args */        public static void Main (string[] args) {System.out.println ("Test start.");        ApplicationContext context = new Classpathxmlapplicationcontext ("Quartz-config.xml");        If the Startquertz Bean's lazy-init is set to False in the configuration file, the//context.getbean ("Startquertz") is not instantiated;    System.out.print ("Test end.."); }} We need to put the log4j configuration file into the SRC directory and start the main class. About cron expressions (from the network): The cron expression consists of the following 7 fields: seconds within the month of the month, date and year (optional fields) 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"Placed in the week Date field indicates 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. field allow value allowed special characters seconds 0-59,-*/min 0-59,-*/hour 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,-*/Expression meaning "0 0 12 * *?" 12 o'clock Noon every day "0 15 10?" * * "10:15 per day" 0 15 10 * * "10:15" 0 15 10 * *? * "Trigger every day 10:15" 0 15 10 * *? 2005 "2005 Years a day 10:15 trigger" 0 * 14 * *? "Every 1 minutes from 2 o'clock in the afternoon to 2:59" 0 0/5 14 * *? "5 0 14,18 * per 0/5 minutes during daily 2 o'clock in the afternoon to 2:55 "0 0-5 14 * Every 5 minutes from 2 o'clock in the afternoon to 2:55 daily and 6 o'clock in the afternoon to 6:55" 1 10,44 0 per 14 minutes during daily 2 o'clock in the afternoon to 2:05? 3 WED "0 15 10 in Wednesday 2:10 and 2:44 per year in March"? * Mon-fri "from Monday to Friday 10:15" 0 15 10 15 *? "15th 10:15" 0 0 L *? "The last day of the month is triggered by 10:15" 15, 10? * 6L "last 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 "The third Friday 10:15 of the month triggers every morning 6 points 0 6 * * * Every two hours 0 */2 * * * * 11 o'clock to 8 hours per two hour in the morning, eight a.m. 0 23-7/2,8 * * * * 4th per month and Monday to Sunday three in the morning 11 11 4 * 1-3 January 1 morning 4 points 0 4 1 1 * More knowledge: HTTP://WWW.IBM.COM/DEVELOPERWorks/cn/java/j-quartz/index.htmlhttp://www.javaeye.com/topic/117244 

Configuration of Spring base quartz

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.