Using Spring Integrated Quartz

Source: Internet
Author: User

Quartz:

The two basic units of the Quartz dispatch pack are job (job) and Trigger (Trigger). A job is an executable task that can be dispatched, and the trigger provides a schedule for the job. Although the two entities are easy to fit together, it is a reason to separate them in the quartz, and it is also beneficial. By separating the work to be performed from its dispatch, Quartz allows the scheduling trigger to be modified without losing the job itself or the context of the job. Also, any single job can have multiple triggers associated with it

Using Spring Integrated Quartz: This system uses spring to integrate quartz. We only need to configure the appropriate trigger and jobs in spring, without having to write any Java code, and spring will automatically start the job when it finds the beans.

Spring configuration: <bean id= "Dumbjob" class= "Org.springframework.scheduling.quartz.JobDetailBean" >

<property name= "group" value= "dumb"/>

<property name= "Jobclass" value= "example. Dumbjob "/>

<property name= "name" value= "Dumbjob"/>

</bean>

<bean id= "Settlementjob" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

<property name= "TargetObject" ref= "Settlementbizfacade"/>

<property name= "Targetmethod" value= "Dosettlement"/>

<property name= "Concurrent" value= "false"/>

<property name= "name" value= "settlement"/>

</bean> <bean id= "Settlementtrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >

<property name= "Jobdetail" ref= "Settlementjob"/>

<!--run at 23:55 everyday--

<property name= "cronexpression" value= "0 55 23 * *?" />

</bean>

<bean class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >

<property name= "Triggers" >

<list> <ref bean= "Settlementtrigger"/>

</list> </property> <property name= "Quartzproperties" >

<map> <!--1 job thread, change the If more jobs added--

<entry key= "Org.quartz.threadPool.threadCount" value= "1"/>

</map>

</property>

</bean>

First we need to configure a job, there are two ways: one is to create a separate jobclass for the job, and then use Spring's Jobdetailbean to configure the job The other is to use Methodinvokingjobdetailfactorybean to specify a method, do not need a separate jobclass, it needs to set "TargetObject" and "Targetmethod", The target method is called when the job is triggered by trigger. Here the "concurrent" is set to "false", the called method does not run in the new thread, but is executed sequentially. Next we configure a cron trigger named "Settlementtrigger" that defines the settlementjob appropriate to be called. Finally, you need to configure the Schedulerfactorybean, which is responsible for scheduling all the trigger, and can also configure the quartz. Because the current task interval is far away, there is no requirement for frequent execution, so the number of threads in quartz is set to "1"

Using Spring Integrated 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.