0

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

1 Answer 1

1

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());
      }
 }
1
  • 3
    Hi @uoyilmaz, I have the similar issue. what is the workerThread here.
    – sohal
    May 17, 2018 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.