Java tutorial
//package com.java2s; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; public class Main { protected static boolean blnStarted; protected static ExecutorService etsContainer; protected static ThreadFactory tdfContainer; public static synchronized void shutdown() { if (blnStarted) { try { getExecutorService().shutdown(); } finally { etsContainer = null; blnStarted = false; } } } protected static synchronized ExecutorService getExecutorService() { return null != etsContainer ? etsContainer : (etsContainer = Executors.newFixedThreadPool(50, getThreadFactory())); } protected static synchronized ThreadFactory getThreadFactory() { return null != tdfContainer ? tdfContainer : (tdfContainer = Executors.defaultThreadFactory()); } }