From 3c2c87364b89de46d12e95abd5bdf8cbd2c6dbf6 Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期三, 12 三月 2025 08:43:23 +0800 Subject: [PATCH] dev-init --- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ThreadPoolConfig.java | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ThreadPoolConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ThreadPoolConfig.java index cb3d8f7..b4d4528 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ThreadPoolConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/config/ThreadPoolConfig.java @@ -1,8 +1,10 @@ package org.dromara.common.core.config; +import jakarta.annotation.PreDestroy; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.dromara.common.core.config.properties.ThreadPoolProperties; import org.dromara.common.core.utils.Threads; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -18,6 +20,7 @@ * * @author Lion Li **/ +@Slf4j @AutoConfiguration @EnableConfigurationProperties(ThreadPoolProperties.class) public class ThreadPoolConfig { @@ -26,6 +29,8 @@ * 鏍稿績绾跨▼鏁� = cpu 鏍稿績鏁� + 1 */ private final int core = Runtime.getRuntime().availableProcessors() + 1; + + private ScheduledExecutorService scheduledExecutorService; @Bean(name = "threadPoolTaskExecutor") @ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true") @@ -44,7 +49,7 @@ */ @Bean(name = "scheduledExecutorService") protected ScheduledExecutorService scheduledExecutorService() { - return new ScheduledThreadPoolExecutor(core, + ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(core, new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(), new ThreadPoolExecutor.CallerRunsPolicy()) { @Override @@ -53,5 +58,21 @@ Threads.printException(r, t); } }; + this.scheduledExecutorService = scheduledThreadPoolExecutor; + return scheduledThreadPoolExecutor; } + + /** + * 閿�姣佷簨浠� + */ + @PreDestroy + public void destroy() { + try { + log.info("====鍏抽棴鍚庡彴浠诲姟浠诲姟绾跨▼姹�===="); + Threads.shutdownAndAwaitTermination(scheduledExecutorService); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + } + } -- Gitblit v1.9.3