From 649adc56427f0d009b58a16d4682d32491e75ae6 Mon Sep 17 00:00:00 2001 From: CJ Date: Sun, 10 Aug 2025 18:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BA=BF=E7=A8=8B=E6=B1=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/framework/config/ThreadPoolConfig.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java index 63739f9c0c..e23b599403 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java @@ -18,16 +18,18 @@ import java.util.concurrent.ThreadPoolExecutor; public class ThreadPoolConfig { // 核心线程池大小 - private int corePoolSize = 50; + private int corePoolSize = Runtime.getRuntime().availableProcessors() * 2; // 最大可创建的线程数 - private int maxPoolSize = 200; + private int maxPoolSize = Runtime.getRuntime().availableProcessors() * 4; // 队列最大长度 - private int queueCapacity = 1000; + private int queueCapacity = 5000; // 线程池维护线程所允许的空闲时间 - private int keepAliveSeconds = 300; + private int keepAliveSeconds = 60; + + private int awaitTerminationMillis = 60; @Bean(name = "threadPoolTaskExecutor") public ThreadPoolTaskExecutor threadPoolTaskExecutor() @@ -37,6 +39,10 @@ public class ThreadPoolConfig executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); + //设置线程池关闭的时候等待所有任务都完成再继续销毁其他的Bean + executor.setWaitForTasksToCompleteOnShutdown(true); + //设置线程池中任务的等待时间,如果超过这个时候还没有销毁就强制销毁,以确保应用最后能够被关闭,而不是阻塞住 + executor.setAwaitTerminationSeconds(awaitTerminationMillis); // 线程池对拒绝任务(无线程可用)的处理策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return executor; -- Gitee