diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 51edf16c48..c1111f9969 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -71,7 +71,7 @@ public class DynamicThreadPoolAutoConfiguration { @Bean @ConditionalOnMissingBean @Order(Ordered.HIGHEST_PRECEDENCE) - public ApplicationContextHolder hippo4JApplicationContextHolder() { + public ApplicationContextHolder hippo4jApplicationContextHolder() { return new ApplicationContextHolder(); } @@ -93,7 +93,7 @@ public ThreadPoolConfigChange defaultThreadPoolConfigChangeHandler(Hippo4jSendMe } @Bean - public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor(ApplicationContextHolder hippo4JApplicationContextHolder) { + public DynamicThreadPoolPostProcessor dynamicThreadPoolPostProcessor() { return new DynamicThreadPoolPostProcessor(bootstrapConfigProperties); } 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 44264686bb..586daf16ec 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 @@ -61,15 +61,14 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof DynamicThreadPoolExecutor || DynamicThreadPoolAdapterChoose.match(bean)) { - DynamicThreadPool dynamicThreadPool; try { - dynamicThreadPool = ApplicationContextHolder.findAnnotationOnBean(beanName, DynamicThreadPool.class); + DynamicThreadPool dynamicThreadPool = + Optional.ofNullable(ApplicationContextHolder.findAnnotationOnBean(beanName, + DynamicThreadPool.class)) + .orElse(DynamicThreadPoolAnnotationUtil.findAnnotationOnBean(beanName, + DynamicThreadPool.class)); if (Objects.isNull(dynamicThreadPool)) { - // Adapt to lower versions of SpringBoot. - dynamicThreadPool = DynamicThreadPoolAnnotationUtil.findAnnotationOnBean(beanName, DynamicThreadPool.class); - if (Objects.isNull(dynamicThreadPool)) { - return bean; - } + return bean; } } catch (Exception ex) { log.error("Failed to create dynamic thread pool in annotation mode.", ex); @@ -79,7 +78,8 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw if ((dynamicThreadPoolExecutor = DynamicThreadPoolAdapterChoose.unwrap(bean)) == null) { dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean; } - DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicThreadPoolExecutor.getThreadPoolId(), dynamicThreadPoolExecutor); + DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicThreadPoolExecutor.getThreadPoolId(), + dynamicThreadPoolExecutor); ThreadPoolExecutor remoteThreadPoolExecutor = fillPoolAndRegister(wrap); DynamicThreadPoolAdapterChoose.replace(bean, remoteThreadPoolExecutor); return DynamicThreadPoolAdapterChoose.match(bean) ? bean : remoteThreadPoolExecutor; @@ -168,7 +168,8 @@ private ExecutorProperties buildDefaultExecutorProperties(String threadPoolId, T * @param executorProperties executor properties */ private void threadPoolParamReplace(ThreadPoolExecutor executor, ExecutorProperties executorProperties) { - BlockingQueue workQueue = BlockingQueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), executorProperties.getQueueCapacity()); + BlockingQueue workQueue = BlockingQueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), + executorProperties.getQueueCapacity()); ReflectUtil.setFieldValue(executor, "workQueue", workQueue); executor.setCorePoolSize(executorProperties.getCorePoolSize()); executor.setMaximumPoolSize(executorProperties.getMaximumPoolSize()); @@ -205,7 +206,8 @@ private ExecutorProperties buildExecutorProperties(ExecutorProperties executorPr .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getQueueCapacity()).get())) .rejectedHandler(Optional.ofNullable(executorProperties.getRejectedHandler()) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getRejectedHandler()).get())) - .threadNamePrefix(StringUtil.isBlank(executorProperties.getThreadNamePrefix()) ? executorProperties.getThreadPoolId() : executorProperties.getThreadNamePrefix()) + .threadNamePrefix(StringUtil.isBlank(executorProperties.getThreadNamePrefix()) ? + executorProperties.getThreadPoolId() : executorProperties.getThreadNamePrefix()) .threadPoolId(executorProperties.getThreadPoolId()) .build(); return newExecutorProperties; @@ -218,7 +220,8 @@ private ExecutorProperties buildExecutorProperties(ExecutorProperties executorPr * @return thread-pool notify alarm */ private ThreadPoolNotifyAlarm buildThreadPoolNotifyAlarm(ExecutorProperties executorProperties) { - DynamicThreadPoolNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); + DynamicThreadPoolNotifyProperties notify = + Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); boolean isAlarm = Optional.ofNullable(executorProperties.getAlarm()) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getAlarm).orElse(true)); int activeAlarm = Optional.ofNullable(executorProperties.getActiveAlarm()) 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 fa290c2d0c..f824797e47 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 @@ -98,7 +98,7 @@ public DynamicThreadPoolBannerHandler threadPoolBannerHandler(ObjectProvider