9
我有一個計劃任務(在固定延遲執行中運行),開始是這樣的:什麼是重新啓動ScheduledExecutorService計劃任務的正確方法?
executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
在週期的每一個開始,我爲您在設置文件的改變,然後我要重新啓動的任務。設置文件還包含間隔的長度(上述代碼中的numOfSeconds
)。
目前,我使用下面的代碼來重新啓動任務:
executoreService.shutdownNow();
try {
while(!executoreService.awaitTermination(5, TimeUnit.SECONDS)){
logger.debug("awaiting termintation");
}
} catch (InterruptedException e) {
logger.debug("interrupted, continuing", e);
}
// initialize startup parameters
init();
// start the main scheduled timer
executoreService.scheduleWithFixedDelay(repeatingThread, 0, numOfSeconds, TimeUnit.SECONDS);
我不知道這些API調用。推薦重新啓動任務的方式是什麼(可能會有新的延遲)?
這是一件需要考慮的事情,但它更容易實現將覆蓋設置更改的任何情況。即設置文件中的任何變化*可能*也會改變延遲。因此,不是檢查延遲是否發生了變化,然後做一件事,如果不是那樣的話,那麼我寧願在任何情況下重新啓動。 – Ovesh 2010-02-16 10:32:30