线程池工具类
如何合理设置线程池核心参数
ThreadPoolUtils.java
public class ThreadPoolUtils {
private static ExecutorService threadPool;
static {
int availableProcessors = Runtime.getRuntime().availableProcessors();
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("pmj-pool-%d").build();
threadPool = new TraceThreadPoolExecutor(availableProcessors, availableProcessors * 10, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(availableProcessors * 100), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
}
public static ExecutorService getThreadPool() {
return threadPool;
}
}
使用实例
ThreadPoolUtils.getThreadPool().submit(() -> {
long startTime = System.currentTimeMillis();
try{
}catch(Exception e){
}finally {
JedisUtil.del(lockKey);
}
System.currentTimeMillis() - startTime;
});