线程池的工具类ThreadPoolUtils
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ThreadPoolUtils {
// 核心线程数
private static final int CORE_POOL_SIZE = 50;
// 最大线程数
private static final int MAX_POOL_ZISE = 1000;
// 存活时间
private static final Long KEEP_ALIVE_TIME = 60L;
private ThreadPoolUtils() {
}
private static class ThreadPoolHolder {
private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_ZISE,
KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}
public static ExecutorService getExecutorService() {
return ThreadPoolHolder.executor;
}
public static void execute(Runnable task) {
ThreadPoolHolder.executor.execute(getExcpThread(task));
}
public static void execute(Runnable runnable, Thread.UncaughtExceptionHandler excpHandler) {