1.线程池基本原理和方法说明:
https://www.cnblogs.com/exe19/p/5359885.html
2.定义枚举类
public enum CommonThreadPool {
INSTANCE;
private ExecutorService instance;
CommonThreadPool(){
instance=new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
Runtime.getRuntime().availableProcessors(),
60L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1000));
}
public ExecutorService getInstanse(){
return instance;
}
}
说明:Runtime.getRuntime().availableProcessors():获取cpu核心数。
3.调用方法
CommonThreadPool.INSTANCE.getInstanse().submit(()-> {
myFunction();
});
说明: