From 23daaa426f38243e7f5e0d0eb153b675a234b0eb Mon Sep 17 00:00:00 2001 From: shiming-stars-lk <1031900093@qq.com> Date: Fri, 15 Jul 2022 19:57:09 +0800 Subject: [PATCH] Hystrix thread pool monitoring optimization --- .../starter/core/ThreadPoolAdapterRegister.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java index bb39ea71..77101f5c 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/ThreadPoolAdapterRegister.java @@ -66,18 +66,16 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { private List cacheConfigList = Lists.newArrayList(); - private static final int TASK_INTERVAL_SECONDS = 2; - @Override public void run(ApplicationArguments args) throws Exception { ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); + int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); + ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds); - ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler); - - scheduler.schedule(threadPoolAdapterRegisterTask, TASK_INTERVAL_SECONDS, TimeUnit.SECONDS); + scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS); } public List getThreadPoolAdapterCacheConfigs(){ @@ -123,8 +121,11 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { private ScheduledExecutorService scheduler; - public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler){ + private int taskIntervalSeconds; + + public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds){ this.scheduler = scheduler; + this.taskIntervalSeconds = taskIntervalSeconds; } @Override @@ -166,7 +167,7 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { log.error("Register Task Error",e); }finally { if (!scheduler.isShutdown()) { - scheduler.schedule(this, TASK_INTERVAL_SECONDS, TimeUnit.MILLISECONDS); + scheduler.schedule(this, taskIntervalSeconds, TimeUnit.MILLISECONDS); } } }