How to run multiple schedulers quartz instances in spring

Source: Internet
Author: User

http://wzping.iteye.com/blog/468263

1. Define a job
<!--use Pojo to do job, specify Pojo and Method--
<bean id= "Jobdetail" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" ref= "Pojoobject"/>
<property name= "Targetmethod" value= "Execute"/>
</bean>

2. Define a trigger time
<bean id= "Crontrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >
<property name= "Jobdetail" ref= "Jobdetail"/>
<!--run every half hour for nine to five working hours--
<property name= "cronexpression" value= "0 0/30 9-17 *,* *?" />
</bean>

3. Definition Manager
<bean name= "Quartzscheduler"
class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Crontrigger"/>
</list>
</property>
</bean>

General application, as long as the configuration above these things can be.

But if there are a lot of timing procedures, and sometimes need to start separately, this time to use two scheduler, in spring is how to achieve it? Simply configuring the two Schedulerfactorybean does not solve the problem. The reasons are as follows:

Take a look at the Schedulerfactorybean code, inside a parameter called: Schedulername,schedulerfactorybean returns a specific scheduler by stdschedulerfactory. And each scheduler is registered in the schedulerrepository.
Each scheduler in the schedulerrepository is placed in a map, based on the name as key.

Private HashMap schedulers;

It's better to do it.
<bean name= "Quartzscheduler"
class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Crontrigger"/>
</list>
</property>
<property name= "Schedulername" ><value>first</value></property>
</bean>
You can declare more than one. and set a different name, so that scheduler have multiple instances, can be started separately, stopped.

How to run multiple schedulers quartz instances in 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.