Search code examples
javac#quartz-schedulerquartz.netjob-scheduling

Shutdown Quartz scheduler after current jobs complete


I am using Quartz for job scheduling in a Windows service. I need to shutdown the scheduler when the service is stopped or when the user changes the frequency of the job runs. As I would like to wait for the executing jobs, I use

scheduler.Shutdown(true);

I get in both cases the exception:

Quartz.UnableToInterruptJobException: Job 'myJob' can not be interrupted, since it does not implement Quartz.IInterruptableJob

The running service cannot be stopped which is quite bad.

But job interruption means not waiting for the job to complete? So, not what I want? Although it would solve the current exception problems.

What would be the correct implementation not causing shutdown to crash?

And if I really need to implement IInterruptableJob, how is this done? I don't find a tutorial about that and I don't really want to do anything different than a standard shutdown. I am using the standard scheduler factory for the scheduler creation:

schedulerFactory = new StdSchedulerFactory();
scheduler = schedulerFactory.GetScheduler();

Solution

  • I found how to interrupt the job... I simply had to implement the IInteruptableJob interface, with an interrupt method doing nothing. This post helped me a lot!