diff options
| author | wanglihui <[email protected]> | 2020-07-21 19:40:25 +0800 |
|---|---|---|
| committer | wanglihui <[email protected]> | 2020-07-21 19:40:25 +0800 |
| commit | 2db192629ad62874287b7ac27728269e27dd1d5f (patch) | |
| tree | 4f9ff3855217659e52e15246f667a0457480417d | |
| parent | b86aa3f5c8e16b35c353973f3d15c9cde242a500 (diff) | |
手动创建连接池
| -rw-r--r-- | IP-learning-graph/src/main/java/cn/ac/iie/utils/ExecutorThreadPool.java | 12 |
1 files 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)) { |
