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 1000304b..64f5399d 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 @@ -171,8 +171,14 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { private void threadPoolParamReplace(ThreadPoolExecutor executor, ExecutorProperties executorProperties) { BlockingQueue workQueue = BlockingQueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), executorProperties.getQueueCapacity()); ReflectUtil.setFieldValue(executor, "workQueue", workQueue); - executor.setCorePoolSize(executorProperties.getCorePoolSize()); - executor.setMaximumPoolSize(executorProperties.getMaximumPoolSize()); + // fix https://github.com/opengoofy/hippo4j/issues/1063 + if (executorProperties.getCorePoolSize() > executor.getMaximumPoolSize()) { + executor.setMaximumPoolSize(executorProperties.getMaximumPoolSize()); + executor.setCorePoolSize(executorProperties.getCorePoolSize()); + } else { + executor.setCorePoolSize(executorProperties.getCorePoolSize()); + executor.setMaximumPoolSize(executorProperties.getMaximumPoolSize()); + } executor.setKeepAliveTime(executorProperties.getKeepAliveTime(), TimeUnit.SECONDS); executor.allowCoreThreadTimeOut(executorProperties.getAllowCoreThreadTimeOut()); executor.setRejectedExecutionHandler(RejectedPolicyTypeEnum.createPolicy(executorProperties.getRejectedHandler())); 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 3362deb0..5d394bc2 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 @@ -178,8 +178,14 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { private void threadPoolParamReplace(ThreadPoolExecutor executor, ThreadPoolParameterInfo threadPoolParameterInfo) { BlockingQueue workQueue = BlockingQueueTypeEnum.createBlockingQueue(threadPoolParameterInfo.getQueueType(), threadPoolParameterInfo.getCapacity()); ReflectUtil.setFieldValue(executor, "workQueue", workQueue); - executor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt()); - executor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt()); + // fix https://github.com/opengoofy/hippo4j/issues/1063 + if (threadPoolParameterInfo.getCorePoolSize() > executor.getMaximumPoolSize()) { + executor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt()); + executor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt()); + } else { + executor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt()); + executor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt()); + } executor.setKeepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS); executor.allowCoreThreadTimeOut(EnableEnum.getBool(threadPoolParameterInfo.getAllowCoreThreadTimeOut())); executor.setRejectedExecutionHandler(RejectedPolicyTypeEnum.createPolicy(threadPoolParameterInfo.getRejectedType()));