我的问题是,当我在集群模式下运行两个tomcat实例时,调度器每10秒调用一次。
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
# 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 = 8QuartzConfig.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()
}
}发布于 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
https://stackoverflow.com/questions/27396163
复制相似问题