From 101099066e7c47e940bbc41829db2ef5c473ca3a Mon Sep 17 00:00:00 2001 From: lijianxin <1064730540@qq.com> Date: Mon, 29 Aug 2022 16:55:26 +0800 Subject: [PATCH] fix: threadNamePrefix is error --- .../starter/support/DynamicThreadPoolPostProcessor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 d506b4d7..4f6ecb76 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 @@ -127,6 +127,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { */ protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrapper) { String threadPoolId = dynamicThreadPoolWrapper.getThreadPoolId(); + ThreadPoolExecutor executor = dynamicThreadPoolWrapper.getExecutor(); Map queryStrMap = new HashMap(3); queryStrMap.put(TP_ID, threadPoolId); queryStrMap.put(ITEM_ID, properties.getItemId()); @@ -144,7 +145,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { newDynamicThreadPoolExecutor = ThreadPoolBuilder.builder() .dynamicPool() .workQueue(workQueue) - .threadFactory(threadPoolId) + .threadFactory(executor.getThreadFactory()) .poolThreadSize(threadPoolParameterInfo.corePoolSizeAdapt(), threadPoolParameterInfo.maximumPoolSizeAdapt()) .keepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS) .rejected(RejectedPolicyTypeEnum.createPolicy(threadPoolParameterInfo.getRejectedType())) @@ -152,7 +153,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { .build(); // Set dynamic thread pool enhancement parameters. ThreadPoolExecutor customDynamicThreadPool; - if ((customDynamicThreadPool = dynamicThreadPoolWrapper.getExecutor()) instanceof AbstractDynamicExecutorSupport) { + if ((customDynamicThreadPool = executor) instanceof AbstractDynamicExecutorSupport) { ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( BooleanUtil.toBoolean(threadPoolParameterInfo.getIsAlarm().toString()), threadPoolParameterInfo.getCapacityAlarm(), @@ -172,11 +173,11 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { } } } catch (Exception ex) { - newDynamicThreadPoolExecutor = dynamicThreadPoolWrapper.getExecutor() != null ? dynamicThreadPoolWrapper.getExecutor() : CommonDynamicThreadPool.getInstance(threadPoolId); + newDynamicThreadPoolExecutor = executor != null ? executor : CommonDynamicThreadPool.getInstance(threadPoolId); dynamicThreadPoolWrapper.setExecutor(newDynamicThreadPoolExecutor); log.error("Failed to initialize thread pool configuration. error message: {}", ex.getMessage()); } finally { - if (Objects.isNull(dynamicThreadPoolWrapper.getExecutor())) { + if (Objects.isNull(executor)) { dynamicThreadPoolWrapper.setExecutor(CommonDynamicThreadPool.getInstance(threadPoolId)); } // Set whether to subscribe to the remote thread pool configuration.