How to configure multiple Quartz single-threaded jobs
I开发者_StackOverflow have 2 different jobs, what must be triggered in the same time.
I'd like to give a separate thread for every of them. Of course i can configure Quartz to use only one thread, setting property
org.quartz.threadPool.threadCount = 1
But it means, that both jobs will be using the same thread. If I set threadCount = 2, it is possible that the first job will be triggered twice, and the other job will wait.
So, how could I run these jobs in separate threads independently?
My Spring configuration is like that:
<bean name="Job1" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="test.job1"/>
</bean>
<bean id="CronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="Job1"/>
<property name="cronExpression" value="0 * 6-21 * * ?" />
</bean>
<bean name="Job2" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="test.job2"/>
</bean>
<bean id="CronTrigger2" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="Job2"/>
<property name="cronExpression" value="0 * 6-21 * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy">
<property name="waitForJobsToCompleteOnShutdown">
<value>true</value>
</property>
<property name="configLocation">
<value>classpath:quartz.properties</value>
</property>
<property name="triggers">
<list>
<ref bean="CronTrigger1"/>
<ref bean="CronTrigger2"/>
</list>
</property>
</bean>
My recommendation is that you use different SchedulerFactoryBeans.
My recommendation is that annotate your job class with @DisallowConcurrentExecution. See the Quartz documentation.
精彩评论