2016-09-27 104 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()); 
     } 
}