@Test public void ExecutorServiceの終了時に実行中のタスクが強制終了されないことを確認() throws InterruptedException { RepairServiceLauncher launcher = new RepairServiceLauncher(); BlockingQueue<Runnable> queue = launcher.executor.getQueue(); assertThat(queue.size(), is(1)); launcher.executor.remove(queue.peek()); Runnable command = new Runnable() { @Override public void run() { try { Thread.sleep(8000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }; launcher.executor.scheduleWithFixedDelay(command, 0, 10, TimeUnit.SECONDS); Thread.sleep(1000); System.out.println("Shutting down service."); long tm1 = System.currentTimeMillis(); launcher.shutdown(); long tm2 = System.currentTimeMillis(); assertTrue(tm2 - tm1 > 4000L); assertThat(launcher.executor.isTerminated(), is(true)); assertThat(launcher.executor.isShutdown(), is(true)); }
public void shutdown() { if (null != executor && !executor.isTerminated()) { logger.info("Shutting down RepairAds scheduler."); executor.shutdown(); try { long awaitShutdownInSec = DcCoreConfig.getAdsRepairAwaitShutdownInSec(); logger.info(String.format("Waiting RepairAds termination up to %d sec.", awaitShutdownInSec)); if (executor.awaitTermination(awaitShutdownInSec, TimeUnit.SECONDS)) { logger.info("Completed shutting down RepairAds scheduler."); } else { logger.warn("Shutting down timed out. RepairAds scheduler have not been terminated."); executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } }
RepairServiceLauncher { public void shutdown() { if (null != executor && !executor.isTerminated()) { logger.info("Shutting down RepairAds scheduler."); executor.shutdown(); try { long awaitShutdownInSec = DcCoreConfig.getAdsRepairAwaitShutdownInSec(); logger.info(String.format("Waiting RepairAds termination up to %d sec.", awaitShutdownInSec)); if (executor.awaitTermination(awaitShutdownInSec, TimeUnit.SECONDS)) { logger.info("Completed shutting down RepairAds scheduler."); } else { logger.warn("Shutting down timed out. RepairAds scheduler have not been terminated."); executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } } }
RepairServiceLauncher { public void shutdown() { if (null != executor && !executor.isTerminated()) { logger.info("Shutting down RepairAds scheduler."); executor.shutdown(); try { long awaitShutdownInSec = DcCoreConfig.getAdsRepairAwaitShutdownInSec(); logger.info(String.format("Waiting RepairAds termination up to %d sec.", awaitShutdownInSec)); if (executor.awaitTermination(awaitShutdownInSec, TimeUnit.SECONDS)) { logger.info("Completed shutting down RepairAds scheduler."); } else { logger.warn("Shutting down timed out. RepairAds scheduler have not been terminated."); executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } } RepairServiceLauncher(); }
RepairServiceLauncher { public void shutdown() { if (null != executor && !executor.isTerminated()) { logger.info("Shutting down RepairAds scheduler."); executor.shutdown(); try { long awaitShutdownInSec = DcCoreConfig.getAdsRepairAwaitShutdownInSec(); logger.info(String.format("Waiting RepairAds termination up to %d sec.", awaitShutdownInSec)); if (executor.awaitTermination(awaitShutdownInSec, TimeUnit.SECONDS)) { logger.info("Completed shutting down RepairAds scheduler."); } else { logger.warn("Shutting down timed out. RepairAds scheduler have not been terminated."); executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } } RepairServiceLauncher(); void shutdown(); }
RepairServiceLauncher { public void shutdown() { if (null != executor && !executor.isTerminated()) { logger.info("Shutting down RepairAds scheduler."); executor.shutdown(); try { long awaitShutdownInSec = DcCoreConfig.getAdsRepairAwaitShutdownInSec(); logger.info(String.format("Waiting RepairAds termination up to %d sec.", awaitShutdownInSec)); if (executor.awaitTermination(awaitShutdownInSec, TimeUnit.SECONDS)) { logger.info("Completed shutting down RepairAds scheduler."); } else { logger.warn("Shutting down timed out. RepairAds scheduler have not been terminated."); executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } } RepairServiceLauncher(); void shutdown();  }