diff --git a/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java b/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java index 17f87182..5a62281a 100644 --- a/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java +++ b/framework/src/main/java/cn/lili/common/utils/ThreadPoolUtil.java @@ -24,7 +24,10 @@ public class ThreadPoolUtil { */ private static final BlockingQueue BQUEUE = new ArrayBlockingQueue(100); private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(SIZE_CORE_POOL, SIZE_MAX_POOL, ALIVE_TIME, TimeUnit.MILLISECONDS, BQUEUE, new ThreadPoolExecutor.CallerRunsPolicy()); - public static ThreadPoolExecutor threadPool; + /** + * volatile禁止指令重排 + */ + public static volatile ThreadPoolExecutor threadPool; static { POOL.prestartAllCoreThreads(); @@ -49,22 +52,20 @@ public class ThreadPoolUtil { } /** - * dcs获取线程池 + * DCL获取线程池 * * @return 线程池对象 */ public static ThreadPoolExecutor getThreadPool() { if (threadPool != null) { return threadPool; - } else { - synchronized (ThreadPoolUtil.class) { - if (threadPool == null) { - threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); - return threadPool; - } - return threadPool; + } + synchronized (ThreadPoolUtil.class) { + if (threadPool == null) { + threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); } } + return threadPool; } public static ThreadPoolExecutor getPool() {