I have a scheduler:

public class Main { private static Scheduler sched; public static void main(String[] args) { BasicConfigurator.configure(); Logger.getLogger("org.apache").setLevel(Level.INFO); try { SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory("quartz.properties"); sched = schedFact.getScheduler(); sched.start(); JobDetail jobDetail; CronTrigger trigger; for (int i = 0; i < 3; i++) { jobDetail = newJob(ReportJob.class) .withIdentity("name" + i, "gr") .build(); jobDetail.getJobDataMap().put("name", "job " + i); trigger = TriggerBuilder.newTrigger() .withIdentity("trigger" + i, "gr") .withSchedule(CronScheduleBuilder.cronSchedule("0 40 14 * * ?") .build(); sched.scheduleJob(jobDetail, trigger); } } catch (Exception e) { System.out.println("Exception while scheduling job" + e); } } } 

and the work itself:

 @DisallowConcurrentExecution public class ReportJob implements Job { public void execute(JobExecutionContext context) throws JobExecutionException { String name = (String) context.getJobDetail().getJobDataMap().get("name"); System.out.println(name + "| job for report started"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(name + "| job for report ended"); } } 

I use quartz-2.2.3 and the @DisallowConcurrentExecution annotation to do the work sequentially, however, the work is nevertheless performed in parallel:

job 0 | job for report started

job 1 | job for report started

job 2 | job for report started

job 0 | job for report ended

job 1 | job for report ended

job 2 | job for report ended

I want the work to be done as follows:

job 0 | job for report started

job 0 | job for report ended

job 1 | job for report started

job 1 | job for report ended

job 2 | job for report started

job 2 | job for report ended

As far as I understand, I need to write a property in the quartz.properties file

 org.quartz.jobStore.misfireThreshold=1 

and add some of the Misfire Instructions . However, none of those that are possible for my trigger:

enter image description here

does not give the desired result. What else do you need to use, besides @DisallowConcurrentExecution , for the sequential execution of work?

    1 answer 1

    I understood my mistake: @DisallowConcurrentExecution prevents multiple instances of a job with the same key ( JobKey ) from being JobKey at the same time. While I used tasks with different keys.