2011-08-08 42 views

回答

0

你可能要考虑的org.quartz.InterruptableJob接口(它扩展了Job)和调度器上的interrupt()方法。

如果您想要在工作线程池中的线程上实际调用Thread.interrupt(),您可能需要实现org.quartz.spi.ThreadPool。

+0

在开始工作之前如何确定任务的使用寿命,并且在到达停止时间的时刻不要调用方法? – cls

+0

您可以随时添加一个作业来杀死其他作业并相应地安排作业。 – Sathwick

0

我认为如果你在作业本身编写了这个功能,你可能会更容易。我这样说的几个原因:

  1. 它很容易跟踪多久的工作已经从作业中
  2. 运行。如果工作需要停下来,它很容易停止正常并预留工作它是做
  3. 你的工作也许能够告诉它做的工程进度,如果其接近完成让它超越杀时间+ 10%或东西
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*/} 
} 

Couple more options are here

相关问题