From db66aa5b91953e1e5c2e2770c45eaa1afdc52bc8 Mon Sep 17 00:00:00 2001 From: "mao.man@rootcloud.com" Date: Fri, 1 Apr 2022 21:21:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=B7=E6=96=B0=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=E6=A0=B8=E5=BF=83=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCoreThreadPoolDynamicRefresh.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/refresher/AbstractCoreThreadPoolDynamicRefresh.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/refresher/AbstractCoreThreadPoolDynamicRefresh.java index db041b04..013f319e 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/refresher/AbstractCoreThreadPoolDynamicRefresh.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/starter/refresher/AbstractCoreThreadPoolDynamicRefresh.java @@ -158,29 +158,11 @@ public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPool if (!checkConsistency(threadPoolId, properties)) { continue; } - + // refresh executor pool dynamicRefreshPool(threadPoolId, properties); - + // old properties ExecutorProperties beforeProperties = GlobalCoreThreadPoolManage.getProperties(properties.getThreadPoolId()); - ChangeParameterNotifyRequest changeRequest = new ChangeParameterNotifyRequest(); - changeRequest.setBeforeCorePoolSize(beforeProperties.getCorePoolSize()); - changeRequest.setBeforeMaximumPoolSize(beforeProperties.getMaximumPoolSize()); - changeRequest.setBeforeAllowsCoreThreadTimeOut(beforeProperties.getAllowCoreThreadTimeOut()); - changeRequest.setBeforeKeepAliveTime(beforeProperties.getKeepAliveTime()); - changeRequest.setBlockingQueueName(beforeProperties.getBlockingQueue()); - changeRequest.setBeforeQueueCapacity(beforeProperties.getQueueCapacity()); - changeRequest.setBeforeRejectedName(beforeProperties.getRejectedHandler()); - changeRequest.setBeforeExecuteTimeOut(beforeProperties.getExecuteTimeOut()); - changeRequest.setThreadPoolId(beforeProperties.getThreadPoolId()); - - changeRequest.setNowCorePoolSize(properties.getCorePoolSize()); - changeRequest.setNowMaximumPoolSize(properties.getMaximumPoolSize()); - changeRequest.setNowAllowsCoreThreadTimeOut(properties.getAllowCoreThreadTimeOut()); - changeRequest.setNowKeepAliveTime(properties.getKeepAliveTime()); - changeRequest.setNowQueueCapacity(properties.getQueueCapacity()); - changeRequest.setNowRejectedName(properties.getRejectedHandler()); - changeRequest.setNowExecuteTimeOut(properties.getExecuteTimeOut()); - + // refresh executor properties GlobalCoreThreadPoolManage.refresh(threadPoolId, properties); log.info( "[{}] Changed thread pool. " + @@ -204,13 +186,41 @@ public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPool ); try { - threadPoolNotifyAlarmHandler.sendPoolConfigChange(changeRequest); + threadPoolNotifyAlarmHandler.sendPoolConfigChange(newChangeRequest(beforeProperties,properties)); } catch (Throwable ex) { log.error("Failed to send change notice. Message :: {}", ex.getMessage()); } } } + /** + * construct ChangeParameterNotifyRequest instance + * + * @param beforeProperties old properties + * @param properties new properties + * @return instance + */ + private ChangeParameterNotifyRequest newChangeRequest(ExecutorProperties beforeProperties, ExecutorProperties properties) { + ChangeParameterNotifyRequest changeRequest = new ChangeParameterNotifyRequest(); + changeRequest.setBeforeCorePoolSize(beforeProperties.getCorePoolSize()); + changeRequest.setBeforeMaximumPoolSize(beforeProperties.getMaximumPoolSize()); + changeRequest.setBeforeAllowsCoreThreadTimeOut(beforeProperties.getAllowCoreThreadTimeOut()); + changeRequest.setBeforeKeepAliveTime(beforeProperties.getKeepAliveTime()); + changeRequest.setBlockingQueueName(beforeProperties.getBlockingQueue()); + changeRequest.setBeforeQueueCapacity(beforeProperties.getQueueCapacity()); + changeRequest.setBeforeRejectedName(beforeProperties.getRejectedHandler()); + changeRequest.setBeforeExecuteTimeOut(beforeProperties.getExecuteTimeOut()); + changeRequest.setThreadPoolId(beforeProperties.getThreadPoolId()); + changeRequest.setNowCorePoolSize(properties.getCorePoolSize()); + changeRequest.setNowMaximumPoolSize(properties.getMaximumPoolSize()); + changeRequest.setNowAllowsCoreThreadTimeOut(properties.getAllowCoreThreadTimeOut()); + changeRequest.setNowKeepAliveTime(properties.getKeepAliveTime()); + changeRequest.setNowQueueCapacity(properties.getQueueCapacity()); + changeRequest.setNowRejectedName(properties.getRejectedHandler()); + changeRequest.setNowExecuteTimeOut(properties.getExecuteTimeOut()); + return changeRequest; + } + /** * Check consistency. *