如何停止 quartz 调度程序中的特定作业我已经阅读了多个类似的问题,但大多数问题没有答案,并且有答案的问题已经过时,并且引用了不再存在的文档
大多数问题的回答是这个 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());
}
}
关于java - 如何停止 quartz 调度程序中的特定作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39733600/