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.

pull/1520/head
MengJinLong 2 years ago
parent 265bf6ed70
commit 7de7918e35

@ -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<ThreadPoolMonitor> 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<String> collectTypes = Arrays.asList(monitor.getCollectTypes().split(","));
ApplicationContextHolder.getBeansOfType(ThreadPoolMonitor.class).forEach((beanName, bean) -> threadPoolMonitors.add(bean));
Collection<DynamicThreadPoolMonitor> dynamicThreadPoolMonitors =
ServiceLoaderRegistry.getSingletonServiceInstances(DynamicThreadPoolMonitor.class);
Collection<ThreadPoolMonitor> 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(

@ -90,6 +90,10 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
*/
private ScheduledThreadPoolExecutor collectVesselExecutor;
static {
ServiceLoaderRegistry.register(ThreadPoolMonitor.class);
}
@SneakyThrows
@Override
public void run() {

Loading…
Cancel
Save