开发者

How to clear triggers in a Quartz Scheduler

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 10开发者_JS百科0 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?


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.


I think your best bet is to just use the shutdown method of the scheduler. You can call scheduler.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜