Java tutorial
//package com.java2s; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import com.google.common.util.concurrent.ThreadFactoryBuilder; public class Main { private static final int CAPACITY = 1000; public static ThreadPoolExecutor newThreadPool(int maximumNumOfThreads, String poolName) { BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(CAPACITY); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maximumNumOfThreads, maximumNumOfThreads, 1, TimeUnit.SECONDS, workQueue, createFactory(poolName)); threadPoolExecutor.allowCoreThreadTimeOut(true); return threadPoolExecutor; } private static ThreadFactory createFactory(String poolName) { return new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build(); } }