石英触发器不会立即触发 [英] Quartz trigger does not fire immediately

查看:61
本文介绍了石英触发器不会立即触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to execute the job ~immediately with quartz scheduler using jdbc datastore. However I have like 20-30 seconds delay between the scheduling and trigger fire even though I schedule with now() or calling triggerJob.

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

I tried to execute the job with a simple trigger:

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);

而且我还尝试使用调度程序触发:

And I also tried to trigger with scheduler:

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


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

这里是显示延迟的监听器日志.

Here are the listener logs that shows the delay.

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

推荐答案

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

I found crumbs here and there that suggested that the problem is transaction related. So I removed @Transactional from the service method and voila it worked. Looks like when you call trigger the scheduler thread asyncronously tries to look up schedules and triggers from the DB but the transaction is not committed at that time. Later the scheduler thread looks up the db again and it finds it finally.

这篇关于石英触发器不会立即触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆