views:

15

answers:

1

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?

+1  A: 

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.

Tommi