tomcat - Grails Quartz Clustering - 调度程序仍然独立运行

标签 tomcat grails quartz-scheduler load-balancing failover

我的问题是,当我使用每 10 秒调用一次的调度程序在集群模式下运行两个 tomcat 实例时

println "called: " + new Date()

然后每个 tomcat 实例都会独立调用该打印。如果我设置 Quartz 配置来处理集群,它不应该是这样的。

例如,当tomcat A 8:00:00 启动,tomcat B 8:00:05 启动,则tomcat A 应该在8:00:10 调用调度器,Tomcat B 应该不是 8:00:15 被叫到。但在我的情况下,调度程序在 8:00:10 触发 tomcat A 和在 8:00:15 触发 tomcat B 然后下一个是在 8:00:20 触发 tomcat A 和在 8:00:25 触发 tomcat B 等等.看起来我的调度程序是独立运行而不是同步的。

这是正确的行为还是我想念的东西?

这是我的配置

quartz 属性
# http://stackoverflow.com/questions/7479438/grails-clustering-quartz-jobs-sample-code-and-config-desired
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = HartakuClusteredScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = quartzDataSource
org.quartz.jobStore.tablePrefix = qrtz_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 5000
org.quartz.jobStore.useProperties = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25

# Detect the jvm shutdown and call shutdown on the scheduler
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true

org.quartz.dataSource.quartzDataSource.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.quartzDataSource.URL = jdbc:mysql://localhost/latihanclust?useUnicode=yes&characterEncoding=UTF-8
org.quartz.dataSource.quartzDataSource.user = root
org.quartz.dataSource.quartzDataSource.password =
org.quartz.dataSource.quartzDataSource.maxConnections = 8

QuartzConfig.groovy
quartz {
    autoStartup = true
    jdbcStore = true
    waitForJobsToCompleteOnShutdown = true
    exposeSchedulerInRepository = false

    props {
        scheduler.skipUpdateCheck = true
    }
}

environments {
    test {
        quartz {
            autoStartup = false
        }
    }
}

TestingJob.groovy
class TestingJob {
    static triggers = {
        simple startDelay:10000, repeatInterval: 10000l // execute job once in 10 seconds
    }

    def execute() {            
        println "called: " + new Date()
    }
}

最佳答案

为什么要使用 Quartz 调度器进行集群?你想达到什么目标?

在我看来,集群应该使用 1 个主服务器和两个或多个从服务器实例来完成。使用 Apache/Nginx 代理转发很容易配置。主服务器位于前面,从属实例位于该主服务器后面。主服务器(如 Apache/Nginx)负责在从属实例之间进行负载平衡或故障转移。

所以,计划是这样的:
用户访问 HTTP Web 端口 80 --> Apache/Nginx Server <---> 代理转发多个 Tomcat 实例(10.1.14.20:8080、10.1.14.21:8080、10.1.14.22:8080 等)。

Apache/Nginx 服务器足够智能,可以检测从属实例。如果一个从属实例宕机,前端网络服务器(Apache/Nginx)继续使用其他仍在运行的从属实例。

引用:
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing

关于tomcat - Grails Quartz Clustering - 调度程序仍然独立运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27396163/

相关文章:

java - 从 14 :00 to 17:30 开始每分钟使用quartz进行调度

tomcat - 无法在 tomcat 容器中运行 redmine 1.1

spring - 如何使用 Tomcat 6 和 Spring 3.0.4 访问 css 文件

Grails:如何根据域 ID 类型动态更改脚手架代码中的方法签名?

Grails 命名查询

grails - 升级后,Grails Quartz Job没有Hibernate session ,从而导致LazyInitializationException

session - 关于 Tomcat session 的问题。 2 war 网络应用程序

tomcat - 如何将消息从 unacked 推送到 ready,rabbitmq

hibernate - Grails GORM如何在指定键上联接旧表

java - 如何为 Quartz 调度程序设置 HSQLDB 架构