如何停止石英调度程序中的特定作业我已经阅读了多个类似的问题,但是大多数问题都没有答案,而那些问题已经过时,并且指的是不再存在的文档
大多数问题中的答复是,该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
但是有没有人有一个如何做到这一点的例子
最佳答案
您可以在此处找到说明: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());
}
}