2011-08-08 43 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

相關問題