Quartz use (Integrated spring)

Source: Internet
Author: User

Quartz with spring, you still need scheduler instances, Jobdetail instances, trigger instances, just created in Factorybean way.

There are corresponding Factorybean classes in the Spring-context-support-xxx.jar package, and scheduler instances correspond to Org.springframework.scheduling.quartz. Schedulerfactorybean. Jobdetail instances correspond to two Factorybean classes, Org.springframework.scheduling.quartz. Jobdetailfactorybean and Org.springframework.scheduling.quartz. Methodinvokingjobdetailfactorybean. trigger instances correspond to two Factorybean classes, Org.springframework.scheduling.quartz. Simpletriggerfactorybean and Org.springframework.scheduling.quartz. Crontriggerfactorybean, Simpletriggerfactorybean corresponds to the generation of Simpletrigger instances, The crontriggerfactorybean corresponds to the generated Crontrigger instance.

Jobdetail instances created with Methodinvokingjobdetailfactorybean are not serializable and are not suitable for persistence of task scheduling information, so if you want to persist task scheduling information, You can only use Jobdetailfactorybean to create jobdetail instances.

These spring configuration files correspond to the following contents:

<BeanID= "Printjobdetail"class= "Org.springframework.scheduling.quartz.JobDetailFactoryBean">        < Propertyname= "Jobclass"value= "Com.kou.quartz.QuartzPrint"/>        < Propertyname= "Durability"value= "false"/></Bean><BeanID= "Printcrontrigger"class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean">        < Propertyname= "Jobdetail"ref= "Printjobdetail"/>        < Propertyname= "Cronexpression"value= "0/5 * * * * * *"/> <!--triggered once every 5 seconds -</Bean><BeanID= "Scheduler"class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean">        <!--specifying the quartz configuration file -        < Propertyname= "Configlocation"value= "Classpath:quartz.properties"/>        <!--quartzscheduler delay start, Quartzscheduler Restart after application start, unit seconds -        < Propertyname= "Startupdelay"value= "1"/>        <!--set up auto-start -        < Propertyname= "Autostartup"value= "true"/>        < Propertyname= "Triggers">            <List>                <refBean= "Printcrontrigger"/>            </List>        </ Property>        < Propertyname= "Overwriteexistingjobs"value= "true"/>        <!--<property name= "DataSource" ref= "DataSource"/> -</Bean>

The Jobclass attribute value of Jobdetailfactorybean is the task class that we develop ourselves, You need to inherit the Org.quartz.Job interface or inherit the Org.springframework.scheduling.quartz.QuartzJobBean.

The Configlocation attribute value of Schedulerfactorybean is the Quartz.properties profile described in the previous article Quartz, which is placed under classpath.

The Overwriteexistingjobs property of Schedulerfactorybean defaults to false, and when trigger is executed every 5 seconds to execute once every 30 seconds, the task schedule is not changed until it is set to true.

Schedulerfactorybean's DataSource property cannot be set, if set, The class that is used to persist task scheduling information becomes a org.springframework.scheduling.quartz.localdatasourcejobstore,quartz.properties file org.quartz.jobStore.cl The "No" configuration item no longer works.

Quartz use (Integrated spring)

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.