Quartz 2.2多调度程序和@DisallowConcurrentExecution [英] Quartz 2.2 multi scheduler and @DisallowConcurrentExecution

查看:62
本文介绍了Quartz 2.2多调度程序和@DisallowConcurrentExecution的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下示例.

一个示例Web应用程序在启动时会调用 scheduler.start().调度程序配置为将其作业存储在DB中.

A sample web application calls scheduler.start() on its start up. The scheduler configured to store its jobs in DB.

该应用程序被复制到六个Web服务器上.

The application is copied on six web-servers.

因此,如果我们启动六个Web服务器,则在单个DB上将有六个具有相同名称的调度程序.如 https://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/MultipleSchedulers :

So if we start six web-servers we will have six scheduler with same name on a single DB. As mentioned in https://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/MultipleSchedulers:

永远不要针对与运行(start()ed)具有相同调度程序名称的任何其他实例的数据库表集相同的数据库表集启动(scheduler.start())非集群实例.您可能会遇到严重的数据损坏,并且肯定会遇到不稳定的行为.

Never start (scheduler.start()) a non-clustered instance against the same set of database tables that any other instance with the same scheduler name is running (start()ed) against. You may get serious data corruption, and will definitely experience erratic behavior.

所以这将失败.

我的问题是,如果我确定我所有的工作都具有 @DisallowConcurrentExecution 可以胜任工作,或者仍然失败?!

My question is that if I am sure that all of my jobs have @DisallowConcurrentExecution will above work or it will still fail ?!

如果 @DisallowConcurrentExecution 没有帮助,我应该手动将一台服务器配置为Master方式

If @DisallowConcurrentExecution does not help, I should do it manually configure one server as some how Master

public class StartUp implements ServletContextListener {

   public void contextInitialized(ServletContextEvent event) {
       if(THIS_IS_MASTER_TOMCAT){
         scheduler.start()
       }
}

还有更好的方法吗?!

推荐答案

基本上,Rene M.是正确的.以下是有争议的Quartz文档:

Basically Rene M. is correct. Here are the docs in question vis-a-vis Quartz:

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

现在从我们自己的公司中使用一些背景知识和概念示例.我们在Wildfly群集内使用 内的石英群集模式.也就是说,每个野生蝇群集节点都运行石英.由于quartz本身以集群模式运行,并且指向相同的数据库模式,因此我们保证每个集群运行一个作业.同样,请参阅文档.关键问题是这样:

Now some background and a conceptual example from our own use at my company. We use quartz clustering mode within a Wildfly Cluster. That is each wildfly cluster node runs quartz. Since quartz is running in cluster mode itself and is pointed at the same database schema we are guaranteed to run one job per cluster. Again, see the documentation. The key issues are this:

  1. 单个石英群集必须针对单个石英数据库运行
    模式.显然,您必须每个创建关系数据库表文档.没关系
  2. 您必须设置quartz.property文件正确,并且副本中必须存在每个节点的副本簇.相同的crystal.property文件
  3. 最后,您必须使用NonJTA数据源,否则石英群集将失败.在Wildfly世界中,这通常意味着石英将需要自己的数据源.

quartz.property示例:

quartz.property example:

    #============================================================================
# Configure Main Scheduler Properties 
#============================================================================

org.quartz.scheduler.instanceName = BjondScheduler
org.quartz.scheduler.instanceId = AUTO

#============================================================================
# Configure ThreadPool 
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5

#============================================================================
# Configure JobStore 
#============================================================================

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 5000

org.quartz.scheduler.wrapJobExecutionInUserTransaction = true
org.quartz.scheduler.userTransactionURL = java:jboss/UserTransaction

org.quartz.jobStore.dataSource = PostgreSQLDS
org.quartz.jobStore.nonManagedTXDataSource = PostgreSQLDSNoJTA

org.quartz.dataSource.PostgreSQLDSNoJTA.jndiURL=java:jboss/datasources/PostgreSQLDSNoJTA
org.quartz.dataSource.PostgreSQLDS.jndiURL=java:jboss/datasources/PostgreSQLDS


#============================================================================
# Configure Logging
#============================================================================
#org.quartz.plugin.jobHistory.class=org.quartz.plugins.history.LoggingJobHistoryPlugin
#org.quartz.plugin.jobHistory.jobToBeFiredMessage=Bjond Job [{1}.{0}] to be fired by trigger [{4}.{3}] at: {2, date, HH:mm:ss MM/dd/yyyy} re-fire count: {7}
#org.quartz.plugin.jobHistory.jobSuccessMessage=Bjond Job [{1}.{0}] execution complete and reports: {8}
#org.quartz.plugin.jobHistory.jobFailedMessage=Bjond Job [{1}.{0}] execution failed with exception: {8}
#org.quartz.plugin.jobHistory.jobWasVetoedMessage=Bjond Job [{1}.{0}] was vetoed. It was to be fired by trigger [{4}.{3}] at: {2, date, dd-MM-yyyy HH:mm:ss.SSS}

现在在standalone.xml中添加我们的数据源代码片段:

Now our datasource snippet within standalone.xml:

            <datasource jta="false" jndi-name="java:jboss/datasources/PostgreSQLDSNoJTA" pool-name="PostgreSQLDSNoJTA" enabled="true" use-java-context="true" use-ccm="true">

您将根据需要填写此数据源元素的其余部分.@DisallowConcurrentExecution是防止在单个节点上执行特定方法的多个作业的好主意,但是石英群集阻止了在多个VM上运行相同的作业.不是这个注释.

You fill in the rest of this datasource element per your requirements. The @DisallowConcurrentExecution is a good idea to prevent multiple jobs on a single node form executing a particular method but it is the quartz clustering that prevents the same job running on multiple VM's; not this annotation.

这篇关于Quartz 2.2多调度程序和@DisallowConcurrentExecution的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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