简体   繁体   中英

How to stop a specific Job in quartz scheduler

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>>) 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

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());
      }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM