Katia
Katia

Reputation: 21

quartz cluster mode only runs one task

I have two quartz apps that must run in cluster mode so I have two jars. When I run those two jars (java -jar) only one process seems to be working, the other seems to be in standby and does nothing and only begins to work when I kill the other process. I need the two processes to run in cluster mode.

This is my config:

private Properties getProperties() {
    final Properties quartzProperties = new Properties();
    quartzProperties.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
    quartzProperties.put("org.quartz.jobStore.isClustered", "true");

    quartzProperties.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
    quartzProperties.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.StdJDBCDelegate");
    quartzProperties.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
    quartzProperties.put("org.quartz.threadPool.threadCount", "25");
    quartzProperties.put("org.quartz.scheduler.instanceId", "AUTO");
    quartzProperties.put("org.quartz.scheduler.instanceName", "qrtz");

    quartzProperties.put("org.quartz.threadPool.threadPriority", "5");
    quartzProperties.put("org.quartz.jobStore.clusterCheckinInterval","10000");
    quartzProperties.put("org.quartz.jobStore.useProperties", "false");


    quartzProperties.put("org.quartz.jobStore.dataSource", "quartzDS");
    quartzProperties.put("org.quartz.dataSource.quartzDS.URL", environment.getRequiredProperty("org.quartz.dataSource.quartzDS.URL"));
    quartzProperties.put("org.quartz.dataSource.quartzDS.user", environment.getRequiredProperty("org.quartz.dataSource.quartzDS.user"));
    quartzProperties.put("org.quartz.dataSource.quartzDS.password", environment.getRequiredProperty("org.quartz.dataSource.quartzDS.password"));
    quartzProperties.put("org.quartz.dataSource.quartzDS.maxConnections", "5");
    quartzProperties.put("org.quartz.dataSource.quartzDS.validationQuery", "select 0 from dual");
    quartzProperties.put("org.quartz.dataSource.quartzDS.driver", environment.getRequiredProperty("org.quartz.dataSource.quartzDS.driver"));
    return quartzProperties;
}

Upvotes: 2

Views: 400

Answers (1)

Kraiss
Kraiss

Reputation: 999

TL;TR : Your problem comes from Quartz Scheduler itself and there is no way to change its behaviour.

To make you understand why, I have to explain you how Quartz cluster mode behaves. We will take your case as example.

You start your two apps which each run a Quartz instance that synchronize through a database. Each jobs you are scheduling is stored in the database with processing data like "last time the job run", "last instance that run the job", etc. Each Quartz instance regularly scans the database for jobs to fire and fires as much jobs it cans.

The things is, if you don't have enough load, one of your node will always scans the database before the other one and take all the load.

To see your other instance working, you have to shutdown or standby the first one or increase the load of the cluster.

The only thing you can configure on this is the size of the thread pool of each node : See http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigJDBCJobStoreClustering.html

Upvotes: 1

Related Questions