Springmvc+quartz simple implementation of timing scheduling

Source: Internet
Author: User

First, Introduction: Quartz is opensymphony open source organization in the Job scheduling field another open source project, it can be combined with the Java EE and J2SE application can also be used alone. Quartz can be used to create a simple or complex program that runs 10, hundreds, or even tens of thousands of jobs. Jobs can be made into standard Java components or EJBs. The latest version of quartz is quartz 2.3.0.

Second, because of the timing of scheduling, in a lot of business will be involved, want to according to their own rules to generate their own want to achieve the purpose. So use quartz to trigger time-timed tasks. is very necessary.

Iii. jar packages required under SPRINGMVC

<Dependency>      <groupId>Org.springframework</groupId>      <Artifactid>Spring-context</Artifactid>      <version>4.3.9.RELEASE</version>    </Dependency>    <Dependency>      <groupId>Org.springframework</groupId>      <Artifactid>Spring-context-support</Artifactid>      <version>4.3.9.RELEASE</version>    </Dependency>    <Dependency>      <groupId>Org.quartz-scheduler</groupId>      <Artifactid>Quartz</Artifactid>      <version>2.2.3</version>    </Dependency>

Description: Quartz is the base package. The Spring-context-support package is a dependent package for the dispatch settings. Spring-context can not be added.

Iv. Configuration of Spring-quartz.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:jdbc= "Http://www.springframework.org/schema/jdbc"Xmlns:jee= "Http://www.springframework.org/schema/jee"Xmlns:tx= "Http://www.springframework.org/schema/tx"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:util= "Http://www.springframework.org/schema/util"XMLNS:JPA= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.3.xsd Http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/ Spring-jdbc-4.3.xsd Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/ Spring-jee-4.3.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-4.3.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA http://www.springframework.org/schema/data/jpa/ Spring-jpa-1.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-4.3.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-4.3.xsd Http://www.springframework.org/schema/util http://www.springframework.org/schema/uTil/spring-util-4.3.xsd " >           <!--join classes that need to be executed -    <BeanID= "Timingschedule"class= "Com.troy.jpa.schedule.TimingSchedule"/>    <!--Join a timed execution method -    <BeanID= "Timingschedulejobdetail"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        <!--class of timed execution -        < Propertyname= "TargetObject"ref= "Timingschedule"/>        <!--the specific method -        < Propertyname= "Targetmethod"value= "Execute"/>    </Bean>    <!--schedule triggers, set the time rules you want -    <BeanID= "Timingscheduletrigger"class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean">        <!--join the relevant execution classes and methods -        < Propertyname= "Jobdetail"ref= "Timingschedulejobdetail"/>        <!--Set the time rule (for easy testing, set it to one minute.) See details for specific rules) -        < Propertyname= "Cronexpression"value= "XX * * * *?"/>        </Bean>    <!--Join the Dispatch factory, set the schedule trigger to -    <Beanclass= "Org.springframework.scheduling.quartz.SchedulerFactoryBean">        < Propertyname= "Triggers">            <List>                <refBean= "Timingscheduletrigger"/>            </List>        </ Property>    </Bean></Beans>

V. Classes and methods that need to be implemented

 Package Com.troy.jpa.schedule; Import java.util.Date;  Public class timingschedule {        // timed execution Method public    void  execute () {        System.out.println (new  Date ());}    }

Vi. Effect of implementation

Execution Time Wed Jul 21:01:00 CST21:02:00 CST21:03:00 CST21:04:00 CST 2 017

Vii. Time Setting rules

1  seconds  is  0-59    ,-*/2  points  is  0-59   ,-*/3 hours  is  0-23   ,-*/4  days  is 
   1-31   ,-*?/5  months  is  1-12 or Jan-dec   ,-*/6  weeks  is  1-7 or sun-sat
   
    , - * ? /
    7  years  no  empty or 1970-2099  
   

Springmvc+quartz simple implementation of timing scheduling

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.