From 2db192629ad62874287b7ac27728269e27dd1d5f Mon Sep 17 00:00:00 2001 From: wanglihui <949764788@qq.com> Date: Tue, 21 Jul 2020 19:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=88=9B=E5=BB=BA=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ac/iie/utils/ExecutorThreadPool.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/IP-learning-graph/src/main/java/cn/ac/iie/utils/ExecutorThreadPool.java b/IP-learning-graph/src/main/java/cn/ac/iie/utils/ExecutorThreadPool.java index 676b887..e7b83ec 100644 --- a/IP-learning-graph/src/main/java/cn/ac/iie/utils/ExecutorThreadPool.java +++ b/IP-learning-graph/src/main/java/cn/ac/iie/utils/ExecutorThreadPool.java @@ -1,12 +1,11 @@ package cn.ac.iie.utils; import cn.ac.iie.config.ApplicationConfig; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; public class ExecutorThreadPool { private static final Logger LOG = LoggerFactory.getLogger(ExecutorThreadPool.class); @@ -18,7 +17,11 @@ public class ExecutorThreadPool { } private static void getThreadPool(){ - pool = Executors.newFixedThreadPool(ApplicationConfig.THREAD_POOL_NUMBER); + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() + .setNameFormat("iplearning-application-pool-%d").build(); + pool = new ThreadPoolExecutor(5, ApplicationConfig.THREAD_POOL_NUMBER, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } public static ExecutorThreadPool getInstance(){ @@ -32,6 +35,7 @@ public class ExecutorThreadPool { pool.execute(command); } + @Deprecated public void awaitThreadTask(){ try { while (!pool.awaitTermination(ApplicationConfig.THREAD_AWAIT_TERMINATION_TIME, TimeUnit.SECONDS)) {