Java tutorial
//package com.java2s; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; public class Main { public static void shutdownAndWaitForever(ExecutorService threadPool) { shutdownAndWait(threadPool, 100500L, TimeUnit.DAYS); } public static void shutdownAndWait(ExecutorService threadPool, long timeout, TimeUnit unit) { threadPool.shutdown(); try { threadPool.awaitTermination(timeout, unit); } catch (InterruptedException e) { throw new RuntimeException(e); } } }