Java tutorial
//package com.java2s; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class Main { private static ThreadPoolExecutor pool = ((ThreadPoolExecutor) Executors.newCachedThreadPool()); public static void shutdown() { try { pool.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("Shutdown was interrupted, forcing shutdown..."); pool.shutdownNow(); e.printStackTrace(); } } }