Every process has a default ThreadPool with defalut size 25 in .Net application development. It is very convenient as writing ThreadPool.QueueUserWorkItem(CallBack);
As so far, I have not found a default tool class to do the same thing in JDK1.6.
So, I try to complete one based on Singleton Model.
public class CustomThreadPool{
private BlockingQueue<Runnable> workQueue;
private ThreadPoolExecutor poolExecutor;
pirvate static CustomThreadPool customThreadPool;
private CustomThreadPool(){
if(workQueue == null){
workQueue = new LinkedBlockingDeque<Runnbale>();
}
if(poolExecutor == null){
poolExecutor = new ThreadPoolExecutor(5, 25, 1, TimeUnit.DAYS, workQueue);
}
}
public static void queueUserWorkItem(Runnble workItem){
if(customThreadPool == null){
customThreadPool = new CustomThreadPoll();
}
customThreadPool.poolExecutor.execute(workItem);
}
}