Java tutorial
//package com.java2s; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class Main { private static ExecutorService executorService = null; private static final Lock lock = new ReentrantLock(); public static final void initPool(int threadSize) { if (null == executorService) { lock.lock(); try { executorService = Executors.newFixedThreadPool(threadSize); } finally { lock.unlock(); } } } }