转载出处:http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html
public class RecvThreadPool {
Logger logger = LoggerFactory.getLogger(RecvThreadPool.class);
private ThreadPoolExecutor pool ;
private ThreadFactory threadFactory = Executors.defaultThreadFactory();
private RejectedExecutionHandlerImpl rejectionHandler = new RejectedExecutionHandlerImpl();
private static RecvThreadPool instance = new RecvThreadPool();
private RecvThreadPool (){
pool = new ThreadPoolExecutor(SystemConfig.getCorePoolSize(), SystemConfig.getMaximumPoolSize(), SystemConfig.getKeepAliveTime(), TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(SystemConfig.getCacheQueueSize()), threadFactory, rejectionHandler);
}
public static RecvThreadPool getInstance(){
return instance;
}
public ThreadPoolExecutor getThreadPoolExecutor(){
return pool;
}
}
本文介绍了一个使用Java实现的线程池示例,通过自定义RecvThreadPool类,展示了如何设置核心线程数、最大线程数、存活时间、任务队列大小等关键参数,并提供了获取线程池实例的方法。
5021

被折叠的 条评论
为什么被折叠?



