2016-09-27 67 views
0

如何停止石英计划程序中的特定作业我已经阅读了多个类似的问题,但大多数问题都没有答案,并且有一个问题已经过时并且涉及到不再存在如何停止石英计划程序中的特定作业

在大多数的问题的答复文件是这个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

但没有任何人有一个如何做到这一点

回答

0

你可以找到一个例子这里的解释: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()); 
     } 
}