From 3b8c1cdc6ae27194cba517d24fe64748db7a1fa4 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 22 May 2022 18:57:58 +0800 Subject: [PATCH] Add get thread pool instance --- .../executor/manage/GlobalThreadPoolManage.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java index 0d09fab9..a511db10 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/manage/GlobalThreadPoolManage.java @@ -23,7 +23,9 @@ import com.google.common.collect.Lists; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadPoolExecutor; /** * Global thread-pool manage. @@ -53,6 +55,16 @@ public class GlobalThreadPoolManage { return EXECUTOR_MAP.get(threadPoolId); } + /** + * Get the dynamic thread pool wrapper class. + * + * @param threadPoolId + * @return + */ + public static ThreadPoolExecutor getExecutor(String threadPoolId) { + return Optional.ofNullable(EXECUTOR_MAP.get(threadPoolId)).map(each -> each.getExecutor()).orElse(null); + } + /** * Get dynamic thread pool parameters. * @@ -106,7 +118,7 @@ public class GlobalThreadPoolManage { /** * Get the number of dynamic thread pools. - * + *

* The data may be inaccurate when the project is initially * launched because registration is done asynchronously. *