立即执行作业
我尝试在用石英安排后立即运行紧急作业。 我的代码如下。我将当前时间指定为 startTime。 Bıt 在计划后运行作业需要 30-40 秒。如何才能立即运行。
// Trigger the job to run now, and then repeat every 40 seconds
jobTrigger= newTrigger()
.withIdentity(Long.toString(emergencyJob.getId()), Long.toString(emergencyJob.getVariant().getId()))
.withPriority(emergencyJob.getPriority())
.startAt(new Date(ctime))
.withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow()
)
.build();
scheduler.scheduleJob(jobDetail, jobTrigger);
I try to run emergency job immediately after scheduled with quartz.
my code is below.I give current time as startTime.
Bıt it takes 30- 40 seconds to run job after schedule.How can run immediately.
// Trigger the job to run now, and then repeat every 40 seconds
jobTrigger= newTrigger()
.withIdentity(Long.toString(emergencyJob.getId()), Long.toString(emergencyJob.getVariant().getId()))
.withPriority(emergencyJob.getPriority())
.startAt(new Date(ctime))
.withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow()
)
.build();
scheduler.scheduleJob(jobDetail, jobTrigger);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用以下命令来触发它:
You can also fire it with:
这只是一个猜测(自从我使用quartz以来已经有一段时间了),但是由于您在实际调用
build()
之前创建了Date
实例,所以它可能不会能够满足该时间限制,并在 40 秒后触发下一个计划的触发器时简单地触发。尝试这样的操作来确认:使用 1000ms 值来满足您的需求。这是为了给它更多的时间来满足第一个预定的触发条件。
This is just a guess (it's been a while since I've used quartz), but since you create the
Date
instance before you actually callbuild()
, it may not be able to meet that time constraint and simply fires 40 seconds later when the next scheduled trigger fires. Try something like this to confirm:Play with the 1000ms value to suit your needs. This is to give it a bit more time to meet the first scheduled trigger.
可能有点晚了,但也许有人会发现这很有用。我在 JBoss AS 上遇到了同样的问题(触发器执行较晚 - 大约 20-30 秒,没有明显的原因)。我得出的结论是,这是由 JBoss 中的某些错误引起的。同样的应用程序在 glassfish 上运行良好。我只更改了 PU 以便使用 eclipse 链接,其他持久性在 JBoss 上运行良好,所以我认为那里没有问题。仅当使用quartz数据库任务存储时才会出现此行为,使用RAM存储则可以正常工作。
来回答问题。如果您使用数据库任务存储,请考虑将其更改为 RAM 存储,这会导致触发器有时被触发。
Probably bit late, but maybe someone will find this useful. I had same issue with quartz on JBoss AS (triggers executed late - approximately 20-30 seconds, for no obvious reason). I came to conclusion that this is caused by some bug in JBoss. Same application worked fine on glassfish. I have changed only PU in order to work with eclipse link and other persistence worked fine on JBoss, so I don't suppose issue there. This behaviour occured only when using quartz database task store, with RAM store it worked fine.
To answear the question. If you use database taskstore, consider changing it to RAM store for me that caused triggers to be fired at time.