gpt4 book ai didi

java - Spring Quartz Scheduler Service 要求仅在单个节点上运行,而不是在所有节点上运行

转载 作者:行者123 更新时间:2023-12-02 06:21:16 24 4
gpt4 key购买 nike

有一个 Spring Web 应用程序 - Yevi。 Yevi部署在具有6个节点的集群环境中。所有节点使用共享的 Yevi 部署包。应用程序在 applicationContext.xml 中有以下配置:

<bean id="cronYeviTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="YeviJob"/>
<!-- run every morning at 6 AM -->
<property name="cronExpression" value="0 0 6 * * ?"/>
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="YeviTrigger"/>
</list>
</property>
<property name="configLocation" value="classpath:quartz.properties"/>
</bean>

而且,quartz.properties 现在什么也没有。上述 CRON 作业设计为每天早上 6 点运行并执行一些业务操作,并在业务操作完成后 sleep 。并且,同时再次醒来并执行相同的业务操作。

我认为该问题与集群环境有关。一旦所有节点都启动并运行。创建了 6 个 CRON 作业 - 每个节点上一个,所需的业务操作执行 6 次,而不是一天一次。

我认为,必须进行某种配置才能在单个节点上仅运行一次而不是在所有节点上运行它。我需要它在早上 6 点仅在一个节点上运行此 CRON 作业,如果该节点已完成,则在故障转移时它应该检查下一个节点并在那里运行 CRON 作业。

谢谢!

最佳答案

使用 JDBC JobStore,您可以通过一个节点实现触发器触发。

http://quartz-scheduler.org/documentation/quartz-2.2.x/configuration/ConfigJDBCJobStoreClustering

编辑

Clustering currently only works with the JDBC-Jobstore (JobStoreTX or JobStoreCMT), and essentially works by having each node of the cluster share the same database.

Load-balancing occurs automatically, with each node of the cluster firing jobs as quickly as it can. When a trigger’s firing time occurs, the first node to acquire it (by placing a lock on it) is the node that will fire it.

Only one node will fire the job for each firing. What I mean by that is, if the job has a repeating trigger that tells it to fire every 10 seconds, then at 12:00:00 exactly one node will run the job, and at 12:00:10 exactly one node will run the job, etc. It won’t necessarily be the same node each time - it will more or less be random which node runs it. The load balancing mechanism is near-random for busy schedulers (lots of triggers) but favors the same node for non-busy (e.g. few triggers) schedulers.

关于java - Spring Quartz Scheduler Service 要求仅在单个节点上运行,而不是在所有节点上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20990490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com