开发者

Are Quartz scheduler instances thread safe?

Can more than one thread safely call methods on an instance of Scheduler returned by the 开发者_运维问答StdSchedulerFactory concurrently?


I had this problem so thought I'd look at the source code. Assuming you are using a standard configuration of Quartz (storing jobs and triggers in RAM instead of a persistent JobStore), then it appears that Quartz is thread safe.

Digging into the source, you will finally get to the RamJobStore, which stores all jobs and triggers in memory.

public void storeJobAndTrigger(SchedulingContext ctxt, JobDetail newJob,
        Trigger newTrigger) throws JobPersistenceException {
    storeJob(ctxt, newJob, false);
    storeTrigger(ctxt, newTrigger, false);
}

In each of the storeJob(..) and storeTrigger(..) methods, there are separate synchronized blocks with their own unique objects for storing jobs and triggers in a thread safe manner:

synchronized (jobLock) {
        if (!repl) {
            // get job group
            ...
        }
    }

And synchronizing a trigger:

synchronized (triggerLock) {
       ...

        synchronized (pausedTriggerGroups) {
            ...
        }
    }

So in short, it would appear that you can make thread safe calls to an instance of the Scheduler class


This post on the Terracotta website confirms it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜