石英触发器不会立即触发

编程入门 行业动态 更新时间:2024-10-11 03:22:00
本文介绍了石英触发器不会立即触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用 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.

更多推荐

石英触发器不会立即触发

本文发布于:2023-10-16 14:18:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   石英

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!