Quartz 调度器行为不一致

Quartz scheduler behaves inconsistently

我有一个带有消息的简单作业 class 和一个执行 5 秒的 setter。此作业 class 由 @DisallowConcurrentExecution 注释,因此无法一次执行多次。

@DisallowConcurrentExecution
public class LongJob implements Job {

    private String message = "Default";
    private int sleepTime = 1000;

    public void setMessage(String message) {
        this.message = message;
    }

    public void setSleepTime(int sleepTime) {
        this.sleepTime = sleepTime;
    }

    public LongJob() {
    }

    @Override
    public void execute(JobExecutionContext context)
            throws JobExecutionException {
        try {
            for (int count = 0; count < 5; count++) {
                Thread.sleep(sleepTime);
                System.out.println(new Date().toString() + " - " + count + ": " + message);
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(LongJob.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

在我的主要方法中,我尝试 运行 这个 class 6 次,每次都有不同的消息。

        SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
        Scheduler sched = schedFact.getScheduler();
        sched.start();

        String name = "LongJob2X";
        JobDetail job = newJob(LongJob.class)
                .withIdentity(name, "group1")
                .storeDurably()
                .requestRecovery(true)
                .build();

        sched.addJob(job, true);

        JobDataMap data = new JobDataMap();
        data.put("message", "Prvy");

        JobDataMap data2 = new JobDataMap();
        data2.put("message", "Druhy");

        JobDataMap data3= new JobDataMap();
        data.put("message", "3");

        JobDataMap data4 = new JobDataMap();
        data.put("message", "stvrty");

        JobDataMap data5 = new JobDataMap();
        data.put("message", "5");

        JobDataMap data6 = new JobDataMap();
        data.put("message", "xsiesty6");

        sched.triggerJob(job.getKey(), data);
        sched.triggerJob(job.getKey(), data2);
        sched.triggerJob(job.getKey(), data3);
        sched.triggerJob(job.getKey(), data4);
        sched.triggerJob(job.getKey(), data5);
        sched.triggerJob(job.getKey(), data6);

令我困惑的是输出。尽管每个触发器的代码都相同,但有时不会调用消息的 setter,因此输出为:

Thu Jan 22 23:32:09 CET 2015 - 0: xsiesty6
Thu Jan 22 23:32:10 CET 2015 - 1: xsiesty6
Thu Jan 22 23:32:11 CET 2015 - 2: xsiesty6
Thu Jan 22 23:32:12 CET 2015 - 3: xsiesty6
Thu Jan 22 23:32:13 CET 2015 - 4: xsiesty6
Thu Jan 22 23:32:14 CET 2015 - 0: Default
Thu Jan 22 23:32:15 CET 2015 - 1: Default
Thu Jan 22 23:32:16 CET 2015 - 2: Default
Thu Jan 22 23:32:17 CET 2015 - 3: Default
Thu Jan 22 23:32:18 CET 2015 - 4: Default
Thu Jan 22 23:32:19 CET 2015 - 0: Default
Thu Jan 22 23:32:20 CET 2015 - 1: Default
Thu Jan 22 23:32:21 CET 2015 - 2: Default
Thu Jan 22 23:32:22 CET 2015 - 3: Default
Thu Jan 22 23:32:23 CET 2015 - 4: Default
Thu Jan 22 23:32:24 CET 2015 - 0: Druhy
Thu Jan 22 23:32:25 CET 2015 - 1: Druhy
Thu Jan 22 23:32:26 CET 2015 - 2: Druhy
Thu Jan 22 23:32:27 CET 2015 - 3: Druhy
Thu Jan 22 23:32:28 CET 2015 - 4: Druhy
Thu Jan 22 23:32:30 CET 2015 - 0: Default
Thu Jan 22 23:32:31 CET 2015 - 1: Default
Thu Jan 22 23:32:32 CET 2015 - 2: Default
Thu Jan 22 23:32:33 CET 2015 - 3: Default
Thu Jan 22 23:32:34 CET 2015 - 4: Default
Thu Jan 22 23:32:35 CET 2015 - 0: Default
Thu Jan 22 23:32:36 CET 2015 - 1: Default
Thu Jan 22 23:32:37 CET 2015 - 2: Default
Thu Jan 22 23:32:38 CET 2015 - 3: Default
Thu Jan 22 23:32:39 CET 2015 - 4: Default

我试过的每个 运行 都只是第二个也是最后一个消息集。一次可以存储多少个 JobDataMaps 是否有限制?还是我做错了什么?谢谢

最后一点:我正在这样使用 JDBC JobStore:

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

这很简单,您几乎每次都将消息放在同一个 data 上,而不是 data.put(...)data2.put(...)data3.put(...)、...

    JobDataMap data = new JobDataMap();
    data.put("message", "Prvy"); //Correct

    JobDataMap data2 = new JobDataMap();
    data2.put("message", "Druhy");// Correct

    JobDataMap data3= new JobDataMap();
    data.put("message", "3");// Here not data3 but data

    JobDataMap data4 = new JobDataMap();
    data.put("message", "stvrty");// Here not data4 but data

    JobDataMap data5 = new JobDataMap();
    data.put("message", "5"); // Here not data5 but data

    JobDataMap data6 = new JobDataMap();
    data.put("message", "xsiesty6");  // Here not data6 but data