Reputation: 659
How to stop a specific Job in quartz scheduler I had read multiple similar question but most of the questions don't have an answer and the ones that Have one are outdated and refers to a documentation that no longer exist
The response in most of the questions are that this You need to write a your job as an implementation of InterruptableJob. To interrupt this job, you need handle to Scheduler, and call interrupt(jobKey<<job name & job group>>)
and the point to this dead link http://www.quartz-scheduler.org/api/2.0.0/org/quartz/InterruptableJob.html
But does anyone have an example of how to do this
Upvotes: 0
Views: 8045
Reputation: 3105
You can find an explanation here: http://forums.terracotta.org/forums/posts/list/7700.page
The relevant part is:
public void interrupt() throws UnableToInterruptJobException
{
stopFlag.set(true);
Thread thread = workerThread.getAndSet(null);
if (thread != null)
thread.interrupt();
}
And you can call it like this:
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = schedulerFactory.getScheduler();
List<JobExecutionContext> currentlyExecuting = scheduler.getCurrentlyExecutingJobs();
for( JobExecutionContext jobExecutionContext : currentlyExecuting)
{
if( jobExecutionContext.getJobDetail().getKey().getName().equals( "Name"))
{
scheduler.interrupt( jobExecutionContext.getJobDetail().getKey());
}
}
Upvotes: 1