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.
精彩评论