Is my approach using Quartz Scheduler's getDefaultScheduler() safe?

118 views Asked by At

I am writing an API that receives requests on when and where to make GET requests, and will then use Quartz to schedule the appropriate times to make those requests. At the moment, I am calling getDefaultScheduler every time a request is made, in order to schedule the appropriate job and trigger. I'm storing the jobs in memory right now, but plan on storing jobs using JDBC later on.

Is this approach safe? We can assume that there may be many concurrent requests to the application, and that the application will make sure there won't be any trigger and job name conflicts.

1

There are 1 answers

0
Srinivas On

Yes they are thread safe. But go ahead and look at the JobStore implementation you are using. Here is the DefaultClusteredJobStore impl for storing jobs..

  public void storeJob(JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException,
  JobPersistenceException {
JobDetail clone = (JobDetail) newJob.clone();

lock();
try {
  // wrapper construction must be done in lock since serializer is unlocked
  JobWrapper jw = wrapperFactory.createJobWrapper(clone);

  if (jobFacade.containsKey(jw.getKey())) {
    if (!replaceExisting) { throw new ObjectAlreadyExistsException(newJob); }
  } else {
    // get job group
    Set<String> grpSet = toolkitDSHolder.getOrCreateJobsGroupMap(newJob.getKey().getGroup());
    // add to jobs by group
    grpSet.add(jw.getKey().getName());

    if (!jobFacade.hasGroup(jw.getKey().getGroup())) {
      jobFacade.addGroup(jw.getKey().getGroup());
    }
  }

  // add/update jobs FQN map
  jobFacade.put(jw.getKey(), jw);
} finally {
  unlock();
}

}