如何安排停止和杀死单个作业的时间 从执行任务的开始? 例如,确定如果一小时后任务仍然有效,它将停止并删除。 (我不是指重复任务) 我在java中使用org.quartz.Scheduler和org.quartz.JobDetail
非常感谢答案 0 :(得分:0)
您可能需要查看org.quartz.InterruptableJob接口(扩展Job)和调度程序上的interrupt()方法。
如果你想在工作线程池中的线程上实际调用Thread.interrupt(),你可能需要实现org.quartz.spi.ThreadPool。
答案 1 :(得分:0)
我认为如果您在作业中编写此功能可能会更容易。我这样说是出于几个原因:
答案 2 :(得分:0)
If you change your class to implement StatefulJob instead of Job, Quartz will take care of this for you. From the StatefulJob javadoc:
stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(xx) method will be delayed.
StatefulJob extends Job and does not add any new methods, so all you need to do to get the behaviour you want is change this:
public class YourJob implements org.quartz.Job {
void execute(JobExecutionContext context) {/*implementation omitted*/}
}
To this:
public class YourJob implements org.quartz.StatefulJob {
void execute(JobExecutionContext context) {/*implementation omitted*/}
}