如何清除 Quartz Scheduler 中的触发器
如果我有一个运行着一堆触发器的 Quartz 调度程序,并且我想清除所有触发器,那么最好如何做到这一点?
我考虑过迭代组和名称,随时调用取消安排,但是当有数千个触发器到位时,这似乎非常慢(取消安排 10 个触发器大约需要 2 秒)。
一个基本的测试用例(调度 1000 个触发器,删除 100 个批次)显示了取消调度操作上调度触发器数量的指数复杂性:
Deleted 100 triggers in 3594ms,35.94 triggers/ms
Deleted 100 triggers in 2734ms,13.67 triggers/ms
Deleted 100 triggers in 2453ms,8.176666666666666 triggers/ms
Deleted 100 triggers in 1985ms,4.9625 triggers/ms
Deleted 100 triggers in 1547ms,3.094 triggers/ms
Deleted 100 triggers in 1281ms,2.135 triggers/ms
Deleted 100 triggers in 1047ms,1.4957142857142858 triggers/ms
Deleted 100 triggers in 765ms,0.95625 triggers/ms
Deleted 100 triggers in 485ms,0.5388888888888889 triggers/ms
Deleted 100 triggers in 156ms,0.156 triggers/ms
我找不到任何类型的批量方法来清除内容。
我最终考虑停止调度程序并将其放松以进行垃圾收集,但我不确定是否还需要清理其他任何内容以确保它不会在任何地方被引用。
有人对这里的最佳方法有看法吗?
If I have a Quartz scheduler running with a bunch of triggers and I want to clear out all the triggers, how is best to do that?
I've considered iterating over the groups and names, calling unschedule as I go, but that seems very slow when there are thousands of triggers in place (around 2s to unschedule 10 triggers).
A rudimentary test case (schedule 1000 triggers, delete batches of 100) shows an exponential complexity w.r.t. the number of scheduled triggers on the unschedule operation:
Deleted 100 triggers in 3594ms,35.94 triggers/ms
Deleted 100 triggers in 2734ms,13.67 triggers/ms
Deleted 100 triggers in 2453ms,8.176666666666666 triggers/ms
Deleted 100 triggers in 1985ms,4.9625 triggers/ms
Deleted 100 triggers in 1547ms,3.094 triggers/ms
Deleted 100 triggers in 1281ms,2.135 triggers/ms
Deleted 100 triggers in 1047ms,1.4957142857142858 triggers/ms
Deleted 100 triggers in 765ms,0.95625 triggers/ms
Deleted 100 triggers in 485ms,0.5388888888888889 triggers/ms
Deleted 100 triggers in 156ms,0.156 triggers/ms
I can't find any kind of bulk methods to clear things out.
I finally considered stopping the scheduler and cutting it loose for garbage collection, but I'm not sure if there's anything else I might need to tidy up to make sure it is not referenced anywhere.
Anyone got a view on the best approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将拥有多少个触发器和工作?
当触发器以类似映射的结构存储在内存中时,对于大量触发器来说,对内存的要求很高,并且触发器越多,操作就越慢。
您考虑过数据库存储吗?您可以受益于 SQL 操作数据集并删除整组触发器或与单个命令匹配模式的所有触发器的能力。
How many triggers and jobs you are going to have?
When triggers are stored in memory in map-like structures, for large numbers of them there is heavy memory requirement and the more triggers, the slower the operations are.
Have you considered database store? You could than profit from SQL ability to operate on set of datas and delete the whole group of triggers, or all triggers matching pattern with single command.
我认为最好的选择是使用调度程序的
shutdown
方法。如果您希望在调度程序关闭之前完成所有当前正在执行的作业,您可以调用scheduler.shutdown(true)
。根据Quartz API,调用shutdown 清理与调度程序关联的所有资源。I think your best bet is to just use the
shutdown
method of the scheduler. You can callscheduler.shutdown(true)
if you want all the currently executing jobs to finish before scheduler is shut down. According to Quartz API, calling shutdown cleans up all resources associated with the Scheduler.