我有一个计划的任务(以固定延迟执行运行),开始如下:
- executoreService.scheduleWithFixedDelay(repeatingThread,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,TimeUnit.SECONDS);