Quartz Spring CronTrigger fired more times than configured

馋奶兔 提交于 2019-12-05 13:29:48
craftsman

I posted same question at springsource forums where I got help to figure out the cause behind the problem: I was loading the application context twice. Later I found from this post how to avoid loading the context twice. Now things are working fine.

This can also happen if you're creating a trigger when you're starting your application and are using a datasource in your quartz.properties file. Every time you start your server it will write a new trigger to the QRTZ_CRON_TRIGGERS and QRTZ_TRIGGERS tables and use all of them on each restart.

Try this:

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronTrigger" />
            </list>
        </property>
    </bean>

    <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" ref="actionObject" />
      <property name="targetMethod" value="actionMethod" />
    </bean>

    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetail"/>
        <property name="cronExpression" value="0 15 17 * * ?"/>
    </bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!