简体   繁体   中英

Interrupting a job in quartz cluster

I have a Quartz setup with multiple instances and I want to interrupt a job wherever it is executed. As it was said in documentation, Scheduler.interrupt() method is not cluster aware so I'm looking for some common practice to overcome such limitation.

Well, here are some basics you should use to achieve that.

When running in cluster mode, the information about the currently running jobs are available in the quartz tables. For instance, the q_fired_triggers contains the job being executed. The first column of this table is the scheduler name being in charge of it. So it is pretty easy to know who is doing what.

Then, if you enable the JMX export of your quartz instances org.quartz.scheduler.jmx.export , the MBeans you will enable a new entry point to remotely manage each scheduler individually. The MBean provides a method boolean interruptJob("JobName", "JobGroup")

Then you " just " need to call this method on the appropriated scheduler instance to effectively interrupt it.

I tried all the process manually and it works fine, just need to be automatized :)

HIH

You are right. The Scheduler.interrupt() does not work in the cluster mode. Let's say that a job trigger is fired by a scheduler in a node but this API is called in another node.

To overcome this, you might use the message broker approach (eg JMS, RabbitMQ, etc.) with publish/subscribe model. Instead of calling Scheduler.interrupt() , the client sends a message of this interruption to the message broker, the payload of the message consists of the identity of the job detail ie JobKey and the name of scheduler ((if there are multiple schedulers used in a node). Then, the message is consumed by all nodes in which the Quartz instance is running, and the nodes find Quartz scheduler by name and then executes Scheduler.interrupt() of the found scheduler with the identity of the job detail taken from the message payload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM