diff --git a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java index cad4d1c0..ec86efe2 100644 --- a/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java +++ b/agent/hippo4j-agent-plugin/spring-plugins/spring-plugin-common/src/main/java/cn/hippo4j/agent/plugin/spring/common/support/SpringThreadPoolRegisterSupport.java @@ -18,7 +18,7 @@ package cn.hippo4j.agent.plugin.spring.common.support; import cn.hippo4j.agent.core.util.ReflectUtil; -import cn.hippo4j.common.executor.ThreadPoolInstanceRegistry; +import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.model.executor.ExecutorProperties; @@ -41,8 +41,8 @@ public class SpringThreadPoolRegisterSupport { private static final Logger LOGGER = LoggerFactory.getLogger(SpringThreadPoolRegisterSupport.class); public static void registerThreadPoolInstances(ApplicationContext context) { - Map> earlyConstructMap = ThreadPoolInstanceRegistry.getInstance().earlyConstructMap; - for (Map.Entry> entry : earlyConstructMap.entrySet()) { + Map> referencedClassMap = ThreadPoolRegistry.getReferencedClassMap(); + for (Map.Entry> entry : referencedClassMap.entrySet()) { ThreadPoolExecutor enhancedInstance = entry.getKey(); Class declaredClass = entry.getValue(); List declaredFields = ReflectUtil.getStaticFieldsFromType(declaredClass, ThreadPoolExecutor.class); @@ -93,6 +93,6 @@ public class SpringThreadPoolRegisterSupport { .queueCapacity(executor.getQueue().remainingCapacity()) .rejectedHandler(RejectedPolicyTypeEnum.getRejectedPolicyTypeEnumByName(executor.getRejectedExecutionHandler().getClass().getSimpleName()).getName()) .build(); - ThreadPoolInstanceRegistry.getInstance().putHolder(threadPoolId, executor, executorProperties); + ThreadPoolRegistry.putHolder(threadPoolId, executor, executorProperties); } } diff --git a/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java b/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java index 98b671fa..d85b0bdc 100644 --- a/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java +++ b/agent/hippo4j-agent-plugin/threadpool-plugin/src/main/java/cn/hippo4j/agent/plugin/thread/pool/interceptor/ThreadPoolExecutorConstructorMethodInterceptor.java @@ -22,7 +22,7 @@ import cn.hippo4j.agent.core.logging.api.ILog; import cn.hippo4j.agent.core.logging.api.LogManager; import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance; import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import cn.hippo4j.common.executor.ThreadPoolInstanceRegistry; +import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.agent.core.util.CollectionUtil; import cn.hippo4j.agent.core.util.StringUtil; import java.util.ArrayList; @@ -52,7 +52,7 @@ public class ThreadPoolExecutorConstructorMethodInterceptor implements InstanceC StackTraceElement declaredClassStackTraceElement = stackTraceElements.get(0); String declaredClassName = declaredClassStackTraceElement.getClassName(); Class declaredClass = Thread.currentThread().getContextClassLoader().loadClass(declaredClassName); - ThreadPoolInstanceRegistry.getInstance().earlyConstructMap.put((ThreadPoolExecutor) objInst, declaredClass); + ThreadPoolRegistry.putReferencedClass((ThreadPoolExecutor) objInst, declaredClass); } private List getStackTraceElements() { diff --git a/infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolInstanceRegistry.java b/infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolRegistry.java similarity index 54% rename from infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolInstanceRegistry.java rename to infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolRegistry.java index a1fbcc82..dbc91917 100644 --- a/infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolInstanceRegistry.java +++ b/infra/common/src/main/java/cn/hippo4j/common/executor/ThreadPoolRegistry.java @@ -27,35 +27,34 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadPoolExecutor; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ThreadPoolInstanceRegistry { +public class ThreadPoolRegistry { - private final Map holderMap = new ConcurrentHashMap<>(); + private static final Map HOLDER_MAP = new ConcurrentHashMap<>(); - public final Map> earlyConstructMap = new ConcurrentHashMap<>(); + public static final Map> REFERENCED_CLASS_MAP = new ConcurrentHashMap<>(); - private volatile static ThreadPoolInstanceRegistry INSTANCE; + public static Map getHolderMap() { + return HOLDER_MAP; + } - public static ThreadPoolInstanceRegistry getInstance() { - if (INSTANCE == null) { - synchronized (ThreadPoolInstanceRegistry.class) { - if (INSTANCE == null) { - INSTANCE = new ThreadPoolInstanceRegistry(); - } - } - } - return INSTANCE; + public static void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties executorProperties) { + ThreadPoolExecutorHolder holder = new ThreadPoolExecutorHolder(executorName, executor, executorProperties); + HOLDER_MAP.put(executorName, holder); } - public Map getHolderMap() { - return holderMap; + public static ThreadPoolExecutorHolder getHolder(String executorName) { + return Optional.ofNullable(HOLDER_MAP.get(executorName)).orElse(ThreadPoolExecutorHolder.EMPTY); } - public void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties executorProperties) { - ThreadPoolExecutorHolder holder = new ThreadPoolExecutorHolder(executorName, executor, executorProperties); - holderMap.put(executorName, holder); + public static Map> getReferencedClassMap() { + return REFERENCED_CLASS_MAP; + } + + public static void putReferencedClass(ThreadPoolExecutor executor, Class referencedClass) { + REFERENCED_CLASS_MAP.put(executor, referencedClass); } - public ThreadPoolExecutorHolder getHolder(String executorName) { - return Optional.ofNullable(holderMap.get(executorName)).orElse(ThreadPoolExecutorHolder.EMPTY); + public static Class getReferencedClass(ThreadPoolExecutor executor) { + return REFERENCED_CLASS_MAP.get(executor); } } diff --git a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java index 36584c56..91df114f 100644 --- a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java +++ b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/refresher/event/DynamicThreadPoolRefreshListener.java @@ -18,7 +18,7 @@ package cn.hippo4j.threadpool.dynamic.mode.config.refresher.event; import cn.hippo4j.common.executor.ThreadPoolExecutorHolder; -import cn.hippo4j.common.executor.ThreadPoolInstanceRegistry; +import cn.hippo4j.common.executor.ThreadPoolRegistry; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum; import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue; @@ -55,7 +55,7 @@ public class DynamicThreadPoolRefreshListener implements Observer