首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grails Quartz集群-调度程序仍然独立运行

Grails Quartz集群-调度程序仍然独立运行
EN

Stack Overflow用户
提问于 2014-12-10 08:16:54
回答 1查看 605关注 0票数 1

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

代码语言:javascript
复制
println "called: " + new Date()

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

例如,当Tomcat A在8:00开始,tomcat B在8:00:05开始时,那么应该在8:00:10在tomcat A中调用调度程序,在8:00:15调用tomcat B,而不是在8:00:15调用tomcat B。但在我的例子中,在tomcat A中触发的调度程序是在8:00:10,而tomcat B是在8:00:15,然后下一个是tomcat A,在8:00:20和tomcat B,在8:00:25等等。看起来我的调度程序是独立运行的,而不是同步运行的。

这是正确的行为还是我错过了什么?

这是我的配置

quartz.properties

代码语言:javascript
复制
# 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

代码语言:javascript
复制
quartz {
    autoStartup = true
    jdbcStore = true
    waitForJobsToCompleteOnShutdown = true
    exposeSchedulerInRepository = false

    props {
        scheduler.skipUpdateCheck = true
    }
}

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

TestingJob.groovy

代码语言:javascript
复制
class TestingJob {
    static triggers = {
        simple startDelay:10000, repeatInterval: 10000l // execute job once in 10 seconds
    }

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

回答 1

Stack Overflow用户

发布于 2014-12-10 10:41:53

为什么要使用Quartz调度程序进行集群?你想达到什么目的?

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

因此,计划如下:用户访问HTTP端口80 -> Apache/Nginx Server <->代理转发多个Tomcat实例(10.1.14.20:8080,10.1.14.21:8080,10.1.14.22:8080,等等)。

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

参考资料:https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27396163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档