如何安排时间从执行任务开始时停止并终止一个作业 ? 例如,确定如果一小时后任务仍在工作,它将停止并移除。 (我并不想重复任务) 我在用java org.quartz.Scheduler和org.quartz.JobDetail使用如何确定在执行过程中停止org.quartz.JobDetail的时间?
千恩万谢
如何安排时间从执行任务开始时停止并终止一个作业 ? 例如,确定如果一小时后任务仍在工作,它将停止并移除。 (我并不想重复任务) 我在用java org.quartz.Scheduler和org.quartz.JobDetail使用如何确定在执行过程中停止org.quartz.JobDetail的时间?
千恩万谢
你可能要考虑的org.quartz.InterruptableJob接口(它扩展了Job)和调度器上的interrupt()方法。
如果您想要在工作线程池中的线程上实际调用Thread.interrupt(),您可能需要实现org.quartz.spi.ThreadPool。
我认为如果你在作业本身编写了这个功能,你可能会更容易。我这样说的几个原因:
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*/}
}
在开始工作之前如何确定任务的使用寿命,并且在到达停止时间的时刻不要调用方法? – cls
您可以随时添加一个作业来杀死其他作业并相应地安排作业。 – Sathwick