Java tutorial
//package com.java2s; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.*; public class Main { public static boolean gracefulShutdown(ExecutorService threadPool, int shutdownTimeoutMills) { if (threadPool == null) { return true; } return MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeoutMills, TimeUnit.MILLISECONDS); } }