quartz scheduler clustering

14,803

According to : http://quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigJDBCJobStoreClustering

in particular :

Clustering currently only works with the JDBC-Jobstore (JobStoreTX or JobStoreCMT), and essentially works by having each node of the cluster share the same database.

Load-balancing occurs automatically, with each node of the cluster firing jobs as quickly as it can. When a trigger's firing time occurs, the first node to acquire it (by placing a lock on it) is the node that will fire it.

You should start all your nodes, the fastest will trigger the job, the others will know about it.

Share:
14,803
kaka
Author by

kaka

I am a senior software engineer

Updated on June 18, 2022

Comments

  • kaka
    kaka almost 2 years

    I have a 2 node HA server. Node 1 is active and node 2 is standby.

    I have made one application and used the quartz api to do clustering. I have made all the tables in the db.

    Now do i need to run the module in both the nodes or jst node 1 so that when the node 1 goes down the application automatically starts in node 2.

    The trigger and the job name should be same or different while running the module in both the nodes?

    Quartz.properties:

    org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool

    org.quartz.threadPool.threadCount = 10

    org.quartz.threadPool.threadPriority = 5

    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

    -- Using RAMJobStore

    -- if using RAMJobStore, please be sure that you comment out

    -- org.quartz.jobStore.tablePrefix, org.quartz.jobStore.driverDelegateClass, org.quartz.jobStore.dataSource

    -org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

    -- Using JobStoreTX

    -- Be sure to run the appropriate script(under docs/dbTables) first to create database/tables

    org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

    -- Using DriverDelegate

    org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate

    --New conf for Clustering

    org.quartz.jobStore.isClustered = true

    org.quartz.jobStore.clusterCheckinInterval = 20000

    org.quartz.scheduler.instanceId = AUTO

    org.quartz.scheduler.instanceId = AUTO

    org.quartz.scheduler.instanceName = MyClusteredScheduler

    -- Configuring JDBCJobStore with the Table Prefix

    org.quartz.jobStore.tablePrefix = QRTZ_

    -- Using datasource

    org.quartz.jobStore.dataSource = qzDS

    -- Define the datasource to use

    org.quartz.dataSource.qzDS.driver = oracle.jdbc.driver.OracleDriver

    org.quartz.dataSource.qzDS.URL = jdbc:oracle:thin:@10.172.16.147:1521:emadb0

    org.quartz.dataSource.qzDS.user = BLuser

    org.quartz.dataSource.qzDS.password = BLuser

    org.quartz.dataSource.qzDS.maxConnections = 30

    -----------------------

  • kaka
    kaka almost 12 years
    But when i run on both the nodes. On the second node i get an error:Unable to store Job with name: 'JOB215na2duosopsg4ddnoZ3s7sd97432918768' and group: 'DEFAULT', because one already exists with this identification.
  • Anthony Dahanne
    Anthony Dahanne almost 12 years
    try this code : if (sched.checkExists(job.getKey())) {sched.rescheduleJob(trigger.getKey(), trigger); } else {sched.scheduleJob(job, trigger); }
  • kaka
    kaka almost 12 years
    Actually what i want is to run the same job in both the nodes of a clustered server. One process should be active at once. If the active process dies, the passive should become active. So as of now i have put the {sched.scheduleJob(job, trigger); } in try catch. And so not scheduling the job if its scheduled once. So does this looks ok?
  • Anthony Dahanne
    Anthony Dahanne almost 12 years
    I understand you want just one node to trigger the jobs at a time, the other node will only be active if the first goes down. The snippet I gave you in my comment will allow the second node to schedule the job, even if the first node already defined it. Try it for yourself !
  • kaka
    kaka almost 12 years
    Ok now i was able to start the job in one node as active and in other node as passive. If the active job dies, the passive job will become active. But now my query is that if the job dies because of server being stopped, so will it come up when the server comes up??
  • Anthony Dahanne
    Anthony Dahanne almost 12 years
    as far as I remember, the job will keep on executing on the active node it is running on