Reputation: 75147
I have followed that tutorial: http://www.mkyong.com/spring/spring-quartz-scheduler-example/
My configuration file is as follows:
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="runMeTask" class="com.mkyong.common.RunMeTask" />
<!-- Spring Quartz -->
<bean id="runMeJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="runMeTask" />
<property name="targetMethod" value="printMe" />
</bean>
<!-- Cron Trigger, run every 5 seconds -->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="runMeJob" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="runMeJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
My printMe function is called at every 5 seconds. However if some delays happens at that function I see that next jobs are queued. However I don't want it. How can I do it at Spring?
Upvotes: 0
Views: 1232
Reputation: 43817
If you want them to run concurrently (e.g. you may have two jobs running at once) then either don't implement StatefulJob
(Quartz < 2.0) or don't use the @DisallowConcurrentExecution
annotation (Quartz >= 2.0).
If you want the second one to not run at all then I don't think Quartz has anything built in. You could use a TriggerListener as described here. Or just modify your job so the first thing it does is check if the previous job finished and return immediately if it hasn't.
Upvotes: 1