Spring + Quartz timed tasks, and modify timed tasks

Source: Internet
Author: User

spring4+quartz2.2.3, scheduled tasks have been fixed, modify the timing task did not toss up, did not find the right solution.

Finally using the library Spring-context-support 3.2.17.RELEASE + quartz 1.8.0 to solve, quart1.8.x version of the Crontriggerbean get up handy

The key code is as follows:

1.maven file

<dependency>            <groupId>org.quartz-scheduler</groupId>            <artifactid>quartz</ artifactid>            <version>1.8.  0</version>        </dependency>        <dependency>            <groupid>org.springframework </groupId>            <artifactId>spring-context-support</artifactId>            <version>3.2 . . Release</version>        </dependency>

2.spring-quartz.xml file

<BeanID= "Scheduleinfoaction"class= "Com.aaa.controller.AutoTaskController">        < Propertyname= "Scheduler"ref= "Schedulerfactory"/>    </Bean>    <BeanID= "Schedulerjobdetail"class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        < Propertyname= "TargetObject"ref= "Scheduleinfoaction"/>        < Propertyname= "Targetmethod"value= "Execute"/>        < Propertyname= "Concurrent"value= "false"/>    </Bean>    <BeanID= "Packetresolvetrigger"class= "Org.springframework.scheduling.quartz.CronTriggerBean" >        < Propertyname= "Jobdetail"ref= "Schedulerjobdetail"/>        < Propertyname= "Cronexpression">            <value>0/5 * * * *?</value>        </ Property>    </Bean>    <BeanID= "Schedulerfactory"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean">        < Propertyname= "Triggers">            <List>                <refLocal= "Packetresolvetrigger"/>            </List>        </ Property>    </Bean>

3.java Code

 Package Com.aaa.controller; @Api ("Timed task Interface") @Controller @requestmapping ("/task")  Public class Autotaskcontroller {
Private Scheduler Scheduler;
public void Setscheduler (Scheduler Scheduler) {
This.scheduler = Scheduler;
}
//Timed task execution    
   protected voidExecute ()throwsException {System.out.println ("Timed task execution, parsing:" +NewDate ()); }
Modify Public voidChangecrontime (String ex)throwsexception{//Get Timer Try{Crontriggerbean Trigger= (Crontriggerbean) scheduler.gettrigger ("Packetresolvetrigger", Scheduler.default_group); System.out.println (Trigger.getcronexpression ()); Trigger.setcronexpression ("0/1 * * * *?"); Scheduler.reschedulejob ("Packetresolvetrigger", Scheduler.default_group, Trigger); } Catch(schedulerexception E1) {e1.printstacktrace (); } Catch(ParseException E1) {e1.printstacktrace (); } }}

Spring + Quartz timed tasks, and modify timed 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.