From 678ec1dd2459c17a0a243f9f42d6ecf99f3dfd9a Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Mon, 24 Oct 2022 21:52:15 +0800 Subject: [PATCH] Code optimization --- .../DynamicThreadPoolAnnotationUtil.java | 16 +++------------- .../support/DynamicThreadPoolPostProcessor.java | 2 +- .../support/DynamicThreadPoolPostProcessor.java | 4 +--- 3 files changed, 5 insertions(+), 17 deletions(-) rename hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/{inet => }/DynamicThreadPoolAnnotationUtil.java (74%) diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/inet/DynamicThreadPoolAnnotationUtil.java b/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/DynamicThreadPoolAnnotationUtil.java similarity index 74% rename from hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/inet/DynamicThreadPoolAnnotationUtil.java rename to hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/DynamicThreadPoolAnnotationUtil.java index 20d267aa..d4555505 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/inet/DynamicThreadPoolAnnotationUtil.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/DynamicThreadPoolAnnotationUtil.java @@ -15,12 +15,11 @@ * limitations under the License. */ -package cn.hippo4j.core.toolkit.inet; +package cn.hippo4j.core.toolkit; import cn.hippo4j.common.config.ApplicationContextHolder; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.support.AbstractApplicationContext; @@ -30,22 +29,13 @@ import java.lang.annotation.Annotation; import java.util.Optional; /** - * {@link DynamicThreadPoolAnnotationUtil} 是为了适配低版本 SpringBoot. - * - *

Spring version >= 5.2.0 下述方法才是有效的, 等同于 SpringBoot version 2.2.0.RELEASE - * {@link ListableBeanFactory#findAnnotationOnBean(java.lang.String, java.lang.Class)} - * - *

但这不是一个优雅的实现方式, 因为其中用到了很多强类型转换, 不确定后续 Spring 升级是否会受影响. - * 不过, 可以确定的是 Spring version < 5.3.14 是没问题的, 等同于 SpringBoot version < 2.6.2 - * - * @author chen.ma - * @date 2022/1/5 21:15 + * Adapted to an earlier version of SpringBoot. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class DynamicThreadPoolAnnotationUtil { /** - * 根据 {@param beanName} 查询注解 {@param annotationType} 是否存在. + * Check for the existence of {@param annotationType} based on {@param beanName}. * * @param beanName bean name * @param annotationType annotation class diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java index c4a92165..04190dd0 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -32,7 +32,7 @@ import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.support.CommonDynamicThreadPool; import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; -import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; +import cn.hippo4j.core.toolkit.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java index 85a19bfd..80d147c5 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -35,7 +35,7 @@ import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.support.*; import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; -import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; +import cn.hippo4j.core.toolkit.DynamicThreadPoolAnnotationUtil; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig; @@ -45,14 +45,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.core.task.TaskDecorator; -import org.springframework.util.ClassUtils; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit;