I am using Quartz scheduler (2.2.1) with MySql as JobStore in a maven based application and I want to implement the clustering feature of Quartz. There are no http calls involved in the task. Hence, I am directly running the jar that are built using fatJar.
I have added the quartz.properties file in the classpath.
#============================================================================
# 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 is different for 2 nodes. Rest everything is same. But when I run the two jars as a cluster, my job is getting executed twice (once by each jar).
My build.gradle looks like this.
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"
}
Is it not possible to have cluster while running the jar directly (java -jar /path/to/jar.jar)? Or am I missing something?
One of the suspect was that my build.gradle did not include quartz-all, quartz-commonj, slf4j jar references (as per http://www.tutorialsavvy.com/2012/12/quartz-scheduler-scheduling-job-in-java.html/). So I added all these references except quartz-all. I cannot find the appropriate jar in maven repository. All jars present in maven are from opensymphony and they don't work with the other quartz related jars that I am using.
Any help will be highly appreciated.
Thanks