From 483e3dd63666587a1f0d1e2c419a6930e9832645 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 28 Nov 2021 21:17:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=20ID=20=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=20Spring=20Bean=20Name.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DynamicExecutorConfigurationSupport.java | 20 ++++++++----------- .../core/DynamicThreadPoolExecutor.java | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java index 8e24f74e..d15ca71b 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicExecutorConfigurationSupport.java @@ -1,7 +1,6 @@ package cn.hippo4j.starter.core; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -15,9 +14,9 @@ import java.util.concurrent.*; */ @Slf4j public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExecutor - implements BeanNameAware, InitializingBean, DisposableBean { + implements InitializingBean, DisposableBean { - private String beanName; + private String threadPoolId; private ExecutorService executor; @@ -32,9 +31,11 @@ public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExec boolean waitForTasksToCompleteOnShutdown, long awaitTerminationMillis, BlockingQueue workQueue, + String threadPoolId, ThreadFactory threadFactory, RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); + this.threadPoolId = threadPoolId; this.waitForTasksToCompleteOnShutdown = waitForTasksToCompleteOnShutdown; this.awaitTerminationMillis = awaitTerminationMillis; } @@ -48,11 +49,6 @@ public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExec */ protected abstract ExecutorService initializeExecutor(); - @Override - public void setBeanName(String name) { - this.beanName = name; - } - /** * Calls {@code initialize()} after the container applied all property values. * @@ -79,7 +75,7 @@ public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExec */ public void initialize() { if (log.isInfoEnabled()) { - log.info("Initializing ExecutorService" + (this.beanName != null ? " '" + this.beanName + "'" : "")); + log.info("Initializing ExecutorService" + (this.threadPoolId != null ? " '" + this.threadPoolId + "'" : "")); } this.executor = initializeExecutor(); @@ -93,7 +89,7 @@ public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExec */ public void shutdownSupport() { if (log.isInfoEnabled()) { - log.info("Shutting down ExecutorService" + (this.beanName != null ? " '" + this.beanName + "'" : "")); + log.info("Shutting down ExecutorService" + (this.threadPoolId != null ? " '" + this.threadPoolId + "'" : "")); } if (this.executor != null) { if (this.waitForTasksToCompleteOnShutdown) { @@ -131,13 +127,13 @@ public abstract class DynamicExecutorConfigurationSupport extends ThreadPoolExec if (!executor.awaitTermination(this.awaitTerminationMillis, TimeUnit.MILLISECONDS)) { if (log.isWarnEnabled()) { log.warn("Timed out while waiting for executor" + - (this.beanName != null ? " '" + this.beanName + "'" : "") + " to terminate"); + (this.threadPoolId != null ? " '" + this.threadPoolId + "'" : "") + " to terminate"); } } } catch (InterruptedException ex) { if (log.isWarnEnabled()) { log.warn("Interrupted while waiting for executor" + - (this.beanName != null ? " '" + this.beanName + "'" : "") + " to terminate"); + (this.threadPoolId != null ? " '" + this.threadPoolId + "'" : "") + " to terminate"); } Thread.currentThread().interrupt(); } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java index 75bd1064..3d5a33c7 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/core/DynamicThreadPoolExecutor.java @@ -72,7 +72,7 @@ public class DynamicThreadPoolExecutor extends DynamicExecutorConfigurationSuppo @NonNull ThreadFactory threadFactory, @NonNull ThreadPoolAlarm threadPoolAlarm, @NonNull RejectedExecutionHandler handler) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, waitForTasksToCompleteOnShutdown, awaitTerminationMillis, workQueue, threadFactory, handler); + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, waitForTasksToCompleteOnShutdown, awaitTerminationMillis, workQueue, threadPoolId, threadFactory, handler); if (corePoolSize < 0 || maximumPoolSize <= 0 ||