public class ThreadPoolManager {
private volatile static ThreadPoolManager threadPoolManager;
private ThreadPoolExecutor threadPool;
private ThreadPoolManager(){
this.threadPool = new ThreadPoolExecutor(16,64,60,
TimeUnit.SECONDS,new ArrayBlockingQueue<>(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));