石英触发器不会立即触发

时间:2019-05-15 14:34:11

标签: java quartz-scheduler

我想使用jdbc数据存储库立即通过石英调度程序执行作业。但是,即使我使用now()或调用triggerJob进行调度,在调度和触发火灾之间也要延迟20-30秒。

我试图用一个简单的触发器来执行作业:

JobKey key = //...
        JobDetail jobDetail = newJob(jobBean.getClass())
                .withIdentity(key)
                .usingJobData(new JobDataMap(jobParams))
                .storeDurably()
                .build();

        Trigger trigger = newTrigger()
                .withIdentity(key.getName(), key.getGroup())
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withMisfireHandlingInstructionFireNow()
                        .withRepeatCount(0))
                .build();

        scheduler.scheduleJob(jobDetail, trigger);

我还尝试使用调度程序进行触发:

 JobKey key = // ...
        JobDetail jobDetail = newJob(jobBean.getClass())
                .withIdentity(key)
                .storeDurably()
                .build();
        scheduler.addJob(jobDetail, true);


        scheduler.triggerJob(key, new JobDataMap(jobParams));

以下是显示延迟的侦听器日志。

2019-05-15 13:59:52,066Z  INFO  [nio-8081-exec-2] c.m.f.s.logger.SchedulingListener                  : Job added: newsJobTemplate:1557928791965
2019-05-15 13:59:52,066Z  INFO  [nio-8081-exec-2] c.m.f.s.logger.SchedulingListener                  : Job scheduled: newsJobTemplate:1557928791965
2019-05-15 14:00:18,660Z  INFO  [eduler_Worker-1] c.m.f.s.logger.TriggerStateListener                : Trigger fired: QUARTZ_JOBS.newsJobTemplate:1557928791965 {}
2019-05-15 14:00:18,703Z  INFO  [eduler_Worker-1] c.m.f.s.logger.JobExecutionListener                : Job will be executed: QUARTZ_JOBS.newsJobTemplate:1557928791965
2019-05-15 14:00:19,284Z  INFO  [eduler_Worker-1] c.m.f.s.logger.JobExecutionListener                : Job was executed: QUARTZ_JOBS.newsJobTemplate:1557928791965

1 个答案:

答案 0 :(得分:1)

我到处都发现面包屑,这表明问题与交易有关。 因此,我从服务方法中删除了@Transactional,并且它起作用了。 看起来像当您调用触发器时,调度程序线程尝试从数据库中查找调度和触发器,但此时未提交事务。稍后,调度程序线程再次查找数据库,并最终找到它。