Java tutorial
//package com.java2s; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Main { private static ExecutorService executorService; private static int maxThreadNum = 40; public static void addRunnable(final Runnable runnable) { initService(); executorService.execute(new Runnable() { public void run() { try { runnable.run(); } catch (Throwable e) { e.printStackTrace(); } } }); } private static void initService() { if (executorService == null) { executorService = Executors.newFixedThreadPool(maxThreadNum); } } }