Quartz群集-服务器启动时触发器重复 [英] Quartz Clustering - triggers duplicated when the server starts

查看:120
本文介绍了Quartz群集-服务器启动时触发器重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在集群设置(带有JDBC数据存储)中将Quartz 2.1.6和Spring 3.1一起使用时,我们面临一个问题。
当前上下文:

We are facing an issue while using Quartz 2.1.6 with Spring 3.1 in a clustered setup (with the JDBC data store). Current context:


  • 作业和CRON触发器在spring配置文件中定义(见下文)

  • overwriteExistingJobs属性在SchedulerFactoryBean中设置为true,因此我们不会在每次部署时都将新的作业定义添加到数据库中。

  • 但是,在集群中的每个部署之后,似乎每个节点都重新创建了触发数据。例如,如果我们有2个触发器指向1个作业和4个节点,则在集群部署之后,数据库具有1个作业定义和4x2触发器。每次重新部署都会添加4x2触发器。

此行为是否正常?如果是:我们如何告诉Quartz不要在每次部署中重新创建触发数据? (或像乔布斯一样覆盖该数据)

Is this behavior normal? If yes: how can we tell Quartz not to re-create trigger data with each deployment? (or overwrite that data, as with Jobs)

<bean name="myJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    <property name="jobClass" value="com.etc.MyJob" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
    p:waitForJobsToCompleteOnShutdown="false" lazy-init="false">

    <property name="dataSource" ref="myDataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="overwriteExistingJobs" value="true" />
    <property name="autoStartup" value="true" />
    <property name="jobFactory">
                <bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory"/>
            </property>
    <property name="triggers">
        <list>
            <bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean" p:cronExpression="0 0 0 * * ?"                   p:misfireInstruction="2">
                <property name="jobDetail" ref="myJob" />
            </bean>
            <bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean "
                p:cronExpression="0 0 20 * * ?"
                p:misfireInstruction="2">
                <property name="jobDetail" ref="myJob" />
            </bean>
        </list>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceName">fsbu_scheduler</prop>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>

            <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
            </prop>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE
            </prop>
            <prop key="org.quartz.jobStore.tablePrefix">fsqrz_</prop>
            <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
            <prop key="org.quartz.threadPool.threadCount">3</prop>
            <prop key="org.quartz.plugin.triggHistory.class">org.quartz.plugins.history.LoggingTriggerHistoryPlugin
            </prop>
            <prop key="org.quartz.plugin.triggHistory.triggerFiredMessage">Trigger {1}.{0} fired job {6}.{5} at {4, date,
                yyyy-MM-dd HH:mm:ss}
            </prop>
            <prop key="org.quartz.plugin.triggHistory.triggerCompleteMessage">Trigger {1}.{0} completed firing job {6}.{5} at {4,
                date, yyyy-MM-dd HH:mm:ss} with resulting trigger instruction code
                {9}
            </prop>
        </props>
    </property>
</bean>


推荐答案

每个触发器的bean定义都没有 名称属性。因此,Spring的CronTriggerFactory每次部署时都会动态生成一个新的触发器名称,这是它引起累加效果的原因(不同名称的触发器不会被覆盖)。

The bean definition for each Trigger did not have the "name" attribute. Therefore, Spring's CronTriggerFactory was dynamically generating a new trigger name with each deployment, being the reason why this caused an additive effect (triggers with different names are not overwritten).

添加每个触发器定义具有唯一值的 name = ... 解决了该问题。

Adding name="..." with an unique value to each trigger definition solved the issue.

这篇关于Quartz群集-服务器启动时触发器重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆