我在基于maven的应用程序中使用Quartz调度程序(2.2.1)和MySql作为JobStore,我想实现Quartz的集群功能。任务中没有涉及http调用。因此,我直接运行使用fatJar构建的jar。
我在类路径中添加了quartz.properties文件。
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = HOST1
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost/mydb
org.quartz.dataSource.myDS.user = user
org.quartz.dataSource.myDS.password = password
org.quartz.dataSource.myDS.validationQuery=select 0 from dual
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000
InstanceId对于2个节点是不同的。休息一切都一样。但是,当我将两个罐作为一个集群运行时,我的工作将被执行两次(每个jar一次)。
我的build.gradle看起来像这样。
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'java'
apply plugin: 'idea'
version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Main-Class': 'com.xxx.xxxxx.Application'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
//Get dependencies from Maven central repository
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
compile "org.jadira.usertype:usertype.core:4.0.0.GA"
compile "org.projectlombok:lombok:1.16.4"
compile "mysql:mysql-connector-java:5.1.35"
compile "org.quartz-scheduler:quartz:2.2.1"
compile "org.quartz-scheduler:quartz-jobs:2.2.1"
compile "org.quartz-scheduler:quartz-commonj:2.1.7"
compile "org.slf4j:slf4j-api:1.7.19"
compile "org.slf4j:slf4j-simple:1.7.19"
compile "org.jdbi:jdbi:2.63.1"
compile "org.antlr:stringtemplate:3.2"
compile "redis.clients:jedis:2.6.3"
compile "ch.qos.logback:logback-classic:1.1.3"
compile "com.rabbitmq:amqp-client:3.5.6"
compile "org.json:json:20150729"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.6.3"
compile "com.fasterxml.jackson.core:jackson-databind:2.6.3"
compile "org.apache.httpcomponents:httpclient:4.5.1"
compile "org.apache.commons:commons-email:1.4"
}
直接运行jar时是不是可以拥有集群(java -jar /path/to/jar.jar)?或者我错过了什么?
其中一个嫌疑人是我的build.gradle没有包含quartz-all,quartz-commonj,slf4j jar引用(根据http://www.tutorialsavvy.com/2012/12/quartz-scheduler-scheduling-job-in-java.html/)。所以我添加了所有这些引用,除了quartz-all。我在maven存储库中找不到合适的jar。所有在maven中存放的罐子都来自opensymphony,他们不和我正在使用的其他石英相关的罐子一起工作。
任何帮助都将受到高度赞赏。
由于