diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraAutoConfiguration.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraAutoConfiguration.java index a856a52b..750b4879 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraAutoConfiguration.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraAutoConfiguration.java @@ -27,8 +27,8 @@ import org.springframework.context.annotation.Configuration; public class ThreadPoolAdapterExtraAutoConfiguration { @Bean - public ThreadPoolAdapterExtra threadPoolAdapterExtra() { - return new ThreadPoolAdapterExtra(); + public ThreadPoolAdapterScheduler threadPoolAdapterExtra() { + return new ThreadPoolAdapterScheduler(); } } diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java deleted file mode 100644 index a6cde2e7..00000000 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtraHandle.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.hippo4j.adapter.base; - -import java.util.Map; - -/** - * Thread Pool Adapter Extra Handle - **/ -@FunctionalInterface -public interface ThreadPoolAdapterExtraHandle { - - void execute(Map map); -} diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtra.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java similarity index 84% rename from hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtra.java rename to hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java index e12fbeaf..2ce8a5d6 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterExtra.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterScheduler.java @@ -19,24 +19,21 @@ package cn.hippo4j.adapter.base; import com.google.common.util.concurrent.ThreadFactoryBuilder; import lombok.extern.slf4j.Slf4j; - -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; /** - * thread pool adapter extra. + * thread pool adapter schedule. */ @Slf4j -public class ThreadPoolAdapterExtra { +public class ThreadPoolAdapterScheduler { + + private static final int TASK_INTERVAL_SECONDS = 2; private final ScheduledExecutorService scheduler; - public ThreadPoolAdapterExtra() { + public ThreadPoolAdapterScheduler() { scheduler = new ScheduledThreadPoolExecutor(2, new ThreadFactoryBuilder() .setNameFormat("threadPoolAdapter") @@ -47,4 +44,8 @@ public class ThreadPoolAdapterExtra { public ScheduledExecutorService getScheduler() { return scheduler; } + + public int getTaskIntervalSeconds(){ + return TASK_INTERVAL_SECONDS; + } } diff --git a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java index e0f53040..2f2e2b1f 100644 --- a/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java +++ b/hippo4j-adapter/hippo4j-adapter-hystrix/src/main/java/cn/hippo4j/adapter/hystrix/HystrixThreadPoolAdapter.java @@ -18,13 +18,11 @@ package cn.hippo4j.adapter.hystrix; import cn.hippo4j.adapter.base.ThreadPoolAdapter; -import cn.hippo4j.adapter.base.ThreadPoolAdapterExtra; +import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; import cn.hippo4j.adapter.base.ThreadPoolAdapterState; -import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.CollectionUtil; import com.google.common.collect.Maps; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.netflix.hystrix.HystrixThreadPool; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationStartedEvent; @@ -32,13 +30,10 @@ import org.springframework.context.ApplicationListener; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -54,15 +49,13 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL private static final String THREAD_POOLS_FIELD = "threadPools"; - private static final int TASK_INTERVAL_SECONDS = 2; - private final Map HYSTRIX_CONSUME_EXECUTOR = Maps.newHashMap(); - private ThreadPoolAdapterExtra threadPoolAdapterExtra; + private ThreadPoolAdapterScheduler threadPoolAdapterScheduler; - public HystrixThreadPoolAdapter(ThreadPoolAdapterExtra threadPoolAdapterExtra) { + public HystrixThreadPoolAdapter(ThreadPoolAdapterScheduler threadPoolAdapterScheduler) { - this.threadPoolAdapterExtra = threadPoolAdapterExtra; + this.threadPoolAdapterScheduler = threadPoolAdapterScheduler; } @@ -113,9 +106,10 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL @Override public void onApplicationEvent(ApplicationStartedEvent event) { - ScheduledExecutorService scheduler = threadPoolAdapterExtra.getScheduler(); - HystrixThreadPoolRefreshTask hystrixThreadPoolRefreshTask = new HystrixThreadPoolRefreshTask(scheduler); - scheduler.schedule(hystrixThreadPoolRefreshTask, TASK_INTERVAL_SECONDS, TimeUnit.SECONDS); + ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); + int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); + HystrixThreadPoolRefreshTask hystrixThreadPoolRefreshTask = new HystrixThreadPoolRefreshTask(scheduler,taskIntervalSeconds); + scheduler.schedule(hystrixThreadPoolRefreshTask, taskIntervalSeconds, TimeUnit.SECONDS); } public void hystrixThreadPoolRefresh() { @@ -151,8 +145,11 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL private ScheduledExecutorService scheduler; - public HystrixThreadPoolRefreshTask(ScheduledExecutorService scheduler) { + private int taskIntervalSeconds; + + public HystrixThreadPoolRefreshTask(ScheduledExecutorService scheduler, int taskIntervalSeconds) { this.scheduler = scheduler; + this.taskIntervalSeconds = taskIntervalSeconds; } @Override @@ -161,7 +158,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL hystrixThreadPoolRefresh(); } finally { if (!scheduler.isShutdown()) { - scheduler.schedule(this, TASK_INTERVAL_SECONDS, TimeUnit.MILLISECONDS); + scheduler.schedule(this, taskIntervalSeconds, TimeUnit.MILLISECONDS); } } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-hystrix/src/main/java/cn/hippo4j/springboot/starter/adapter/hystrix/HystrixAdapterAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-hystrix/src/main/java/cn/hippo4j/springboot/starter/adapter/hystrix/HystrixAdapterAutoConfiguration.java index 5d8a9243..2873f04d 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-hystrix/src/main/java/cn/hippo4j/springboot/starter/adapter/hystrix/HystrixAdapterAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-hystrix/src/main/java/cn/hippo4j/springboot/starter/adapter/hystrix/HystrixAdapterAutoConfiguration.java @@ -17,7 +17,7 @@ package cn.hippo4j.springboot.starter.adapter.hystrix; -import cn.hippo4j.adapter.base.ThreadPoolAdapterExtra; +import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; import cn.hippo4j.adapter.base.ThreadPoolAdapterExtraAutoConfiguration; import cn.hippo4j.adapter.hystrix.HystrixThreadPoolAdapter; import cn.hippo4j.common.config.ApplicationContextHolder; @@ -43,7 +43,7 @@ public class HystrixAdapterAutoConfiguration { } @Bean - public HystrixThreadPoolAdapter hystrixThreadPoolAdapter(ThreadPoolAdapterExtra threadPoolAdapterExtra) { - return new HystrixThreadPoolAdapter(threadPoolAdapterExtra); + public HystrixThreadPoolAdapter hystrixThreadPoolAdapter(ThreadPoolAdapterScheduler threadPoolAdapterScheduler) { + return new HystrixThreadPoolAdapter(threadPoolAdapterScheduler); } } diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index d218a7e4..f8b512ba 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -18,7 +18,7 @@ package cn.hippo4j.springboot.starter.config; import cn.hippo4j.adapter.base.ThreadPoolAdapterBeanContainer; -import cn.hippo4j.adapter.base.ThreadPoolAdapterExtra; +import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; import cn.hippo4j.common.api.ThreadDetailState; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.core.config.UtilAutoConfiguration; @@ -166,7 +166,7 @@ public class DynamicThreadPoolAutoConfiguration { @Bean @SuppressWarnings("all") - public ThreadPoolAdapterRegister threadPoolAdapterRegister(HttpAgent httpAgent, InetUtils hippo4JInetUtils, ThreadPoolAdapterExtra threadPoolAdapterExtra) { - return new ThreadPoolAdapterRegister(httpAgent, properties, environment, hippo4JInetUtils, threadPoolAdapterExtra); + public ThreadPoolAdapterRegister threadPoolAdapterRegister(HttpAgent httpAgent, InetUtils hippo4JInetUtils, ThreadPoolAdapterScheduler threadPoolAdapterScheduler) { + return new ThreadPoolAdapterRegister(httpAgent, properties, environment, hippo4JInetUtils, threadPoolAdapterScheduler); } } 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 f855dc9f..bb39ea71 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 @@ -19,7 +19,7 @@ package cn.hippo4j.springboot.starter.core; import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig; -import cn.hippo4j.adapter.base.ThreadPoolAdapterExtra; +import cn.hippo4j.adapter.base.ThreadPoolAdapterScheduler; import cn.hippo4j.adapter.base.ThreadPoolAdapterState; import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.toolkit.CollectionUtil; @@ -62,7 +62,7 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { private final InetUtils hippo4JInetUtils; - private final ThreadPoolAdapterExtra threadPoolAdapterExtra; + private final ThreadPoolAdapterScheduler threadPoolAdapterScheduler; private List cacheConfigList = Lists.newArrayList(); @@ -73,7 +73,7 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { - ScheduledExecutorService scheduler = threadPoolAdapterExtra.getScheduler(); + ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler);