不要在Spring Quartz排队工作

时间:2013-06-17 14:36:48

标签: spring quartz-scheduler jobs

我已按照该教程:http://www.mkyong.com/spring/spring-quartz-scheduler-example/

我的配置文件如下:

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>

我的printMe功能每5秒调用一次。但是,如果在该功能发生一些延迟,我会看到下一个作业排队。但是我不想要它。我怎么能在春天做到这一点?

1 个答案:

答案 0 :(得分:1)

如果您希望它们同时运行(例如,您可能同时运行两个作业),则要么不实现StatefulJob(Quartz&lt; 2.0),要么不使用@DisallowConcurrentExecution注释(Quartz&gt; = 2.0)。

如果你想让第二个没有运行那么我认为Quartz没有任何内置的东西。你可以使用如here所述的TriggerListener。或者只是修改你的工作,这样做的第一件事就是检查上一个工作是否完成,如果没有,则立即返回。

相关问题