public class ThreadPoolManager {
private volatile static ThreadPoolManager threadPoolManager;
private ThreadPoolExecutor threadPool;
private ThreadPoolManager(){
this.threadPool = new ThreadPoolExecutor(16,64,60,
TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(1000),new ThreadPoolExecutor.DiscardPolicy());
}
public static ThreadPoolManager getInstance() {
if (threadPoolManager == null){
synchronized (ThreadPoolManager.class){
if(threadPoolManager == null){
threadPoolManager = new ThreadPoolManager();
}
}
}
return threadPoolManager;
}
public ThreadPoolExecutor getThreadPool() {
return threadPool;
}
}
//使用
ThreadPoolManager.getInstance().getThreadPool().execute(()->{
System.out.println(111);
});
线程池的构建及使用
最新推荐文章于 2024-07-27 13:31:57 发布