【问题标题】:How to stop a specific Job in quartz scheduler如何在石英调度程序中停止特定作业
【发布时间】:2017-02-05 14:42:48
【问题描述】:

How to stop a specific Job in quartz scheduler 我已经阅读了多个类似的问题,但大多数问题都没有答案,而有一个问题的问题已经过时,并且参考了不再存在的文档

大部分问题的回答是这个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>>)和指向这个死链接http://www.quartz-scheduler.org/api/2.0.0/org/quartz/InterruptableJob.html

但是有没有人有例子说明如何做到这一点

【问题讨论】:

    标签: java scheduled-tasks quartz-scheduler


    【解决方案1】:

    你可以在这里找到解释:http://forums.terracotta.org/forums/posts/list/7700.page

    相关部分是:

     public void interrupt() throws UnableToInterruptJobException
     {
         stopFlag.set(true);
         Thread thread = workerThread.getAndSet(null);
         if (thread != null)
             thread.interrupt();
     }
    

    你可以这样称呼它:

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

    【讨论】:

    • 嗨@uoyilmaz,我有类似的问题。这里的workerThread是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多