I created a Spring application with two quartz schedulers with the first having 3 triggers and second having one trigger.
All those triggers are set to concurrent operation false.
When I run this, it seems like only the trigger of the job in the second scheduler get fired. The triggerJobB takes very little time to execute too.
My question is that does using two schedulers in one spring context cause executing problems and whether it's a good practice.
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="triggerJobA" />
<ref bean="triggerJobC" />
<ref bean="triggerJobD" />
</list>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="triggerJobB" />
</list>
</property>
</bean>
You need to set the name for each scheduler, otherwise spring just overwrites the first scheduler with the second one.
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerName" value="SchedulerOne"/>
<property name="triggers">
<list>
<ref bean="triggerJobA" />
<ref bean="triggerJobC" />
<ref bean="triggerJobD" />
</list>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerName" value="SchedulerTwo"/>
<property name="triggers">
<list>
<ref bean="triggerJobB" />
</list>
</property>
</bean>
Reason for this is:
The "job executor" is actually not the SchedulerFactoryBean. It is the Scheduler bean(to be precise calling its start method invokes the aggregated QuartzScheduler.start method which fires the Trigger-s), provided by the SchedulerFactoryBean. As a matter of fact this Scheduler is stored(and looked-up) under the schedulerName(which if not explicitly set has the same default value for every configured SchedulerFactoryBean) in the SchedulerRepository singleton(SchedulerRepository.getInstance()).
That's how unless you set a different schedulerName for your SchedulerFactoryBean-s, you will always get the same scheduler by each and every SchedulerFactoryBean-s
http://forum.springsource.org/showthread.php?40945-Multiple-Quartz-SchedulerFactoryBean-instances
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With