我想使用 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.
更多推荐
石英触发器不会立即触发
发布评论