From 1e81da19791e39a411fde7c748ae38e8a4fe6585 Mon Sep 17 00:00:00 2001 From: yezi <86636468+Dawanyezhi@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:09:46 +0800 Subject: [PATCH] fix:Fix the problem that the ThreadPoolMonitor interface SPI mechanism is not injected in the config mode, and modify the solution in the server mode. (#1520) --- .../starter/monitor/ThreadPoolMonitorExecutor.java | 9 ++++++--- .../starter/monitor/ReportingEventExecutor.java | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java index a9cce9b0..8cdec513 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/monitor/ThreadPoolMonitorExecutor.java @@ -24,7 +24,6 @@ import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.core.config.ApplicationContextHolder; import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties; import cn.hippo4j.threadpool.dynamic.mode.config.properties.MonitorProperties; -import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor; import cn.hippo4j.threadpool.monitor.api.ThreadPoolMonitor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -53,6 +52,10 @@ public class ThreadPoolMonitorExecutor implements ApplicationRunner, DisposableB private List threadPoolMonitors; + static { + ServiceLoaderRegistry.register(ThreadPoolMonitor.class); + } + @Override public void run(ApplicationArguments args) throws Exception { MonitorProperties monitor = properties.getMonitor(); @@ -70,8 +73,8 @@ public class ThreadPoolMonitorExecutor implements ApplicationRunner, DisposableB // Get dynamic thread pool monitoring component. List collectTypes = Arrays.asList(monitor.getCollectTypes().split(",")); ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class).forEach((beanName, bean) -> threadPoolMonitors.add(bean)); - Collection dynamicThreadPoolMonitors = - ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolMonitor.class); + Collection dynamicThreadPoolMonitors = + ServiceLoaderRegistry.getSingletonServiceInstances(ThreadPoolMonitor.class); dynamicThreadPoolMonitors.stream().filter(each -> collectTypes.contains(each.getType())).forEach(each -> threadPoolMonitors.add(each)); // Execute dynamic thread pool monitoring component. collectScheduledExecutor.scheduleWithFixedDelay( diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java index 440a68b3..981ea3d5 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/monitor/ReportingEventExecutor.java @@ -87,6 +87,10 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp */ private ScheduledThreadPoolExecutor collectVesselExecutor; + static { + ServiceLoaderRegistry.register(ThreadPoolMonitor.class); + } + @SneakyThrows @Override public void run() {