From c39403a0d24367003ccc538aafa5cde6b809c2fa Mon Sep 17 00:00:00 2001 From: dataprince Date: Sun, 14 Jan 2024 10:22:02 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"web=E5=AE=B9=E5=99=A8=E4=BB=8Eunderto?= =?UTF-8?q?w=E5=88=87=E6=8D=A2=E5=88=B0tomcat=EF=BC=8C=E6=9B=B4=E5=A5=BD?= =?UTF-8?q?=E5=9C=B0=E6=94=AF=E6=8C=81=E8=99=9A=E6=8B=9F=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9c8de8afbf75c0ca1a6ffd726b523e7697bc0487. --- pom.xml | 2 +- .../src/main/resources/application.yml | 9 ++++++ .../common/core/config/ApplicationConfig.java | 3 +- .../ruoyi/common/core/config/AsyncConfig.java | 5 ++-- .../common/core/config/ThreadPoolConfig.java | 17 +++++++++++ .../properties/ThreadPoolProperties.java | 30 +++++++++++++++++++ 6 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/properties/ThreadPoolProperties.java diff --git a/pom.xml b/pom.xml index 9a13a86..b49ffb3 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ 0.2.0 5.8.24 3.25.2 - 2.2.7 + 2.2.4 2.14.4 3.2.0 4.3.6 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index ab54a02..a26eb42 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -245,6 +245,15 @@ xss: # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/*,/demo/* +# 全局线程池相关配置 +thread-pool: + # 是否开启线程池 + enabled: false + # 队列最大长度 + queueCapacity: 128 + # 线程池维护线程所允许的空闲时间 + keepAliveSeconds: 300 + # 分布式锁 lock4j 全局配置 lock4j: # 获取分布式锁超时时间,默认为 3000 毫秒 diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ApplicationConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ApplicationConfig.java index f0a482c..0bfa503 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ApplicationConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ApplicationConfig.java @@ -2,7 +2,6 @@ package com.ruoyi.common.core.config; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.scheduling.annotation.EnableAsync; /** * 程序注解配置 @@ -12,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableAsync; @AutoConfiguration // 表示通过aop框架暴露该代理对象,AopContext能够访问 @EnableAspectJAutoProxy(exposeProxy = true) -@EnableAsync(proxyTargetClass = true) +// 指定要扫描的Mapper类的包的路径 public class ApplicationConfig { diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/AsyncConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/AsyncConfig.java index 1da6342..14dc801 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/AsyncConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/AsyncConfig.java @@ -5,8 +5,8 @@ import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.SpringUtils; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.annotation.EnableAsync; import java.util.Arrays; import java.util.concurrent.Executor; @@ -14,10 +14,9 @@ import java.util.concurrent.Executor; /** * 异步配置 * - * 如果未使用虚拟线程则生效 * @author Lion Li */ -@ConditionalOnProperty(prefix = "spring.threads.virtual", name = "enabled", havingValue = "false") +@EnableAsync(proxyTargetClass = true) @AutoConfiguration public class AsyncConfig implements AsyncConfigurer { diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ThreadPoolConfig.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ThreadPoolConfig.java index 033f67b..727ad67 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ThreadPoolConfig.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/ThreadPoolConfig.java @@ -1,11 +1,15 @@ package com.ruoyi.common.core.config; +import com.ruoyi.common.core.config.properties.ThreadPoolProperties; import com.ruoyi.common.core.utils.Threads; import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; 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; import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; @@ -17,6 +21,7 @@ import java.util.concurrent.ThreadPoolExecutor; **/ @Slf4j @AutoConfiguration +@EnableConfigurationProperties(ThreadPoolProperties.class) public class ThreadPoolConfig { /** @@ -26,6 +31,18 @@ public class ThreadPoolConfig private ScheduledExecutorService scheduledExecutorService; + @Bean(name = "threadPoolTaskExecutor") + @ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true") + public ThreadPoolTaskExecutor threadPoolTaskExecutor(ThreadPoolProperties threadPoolProperties) { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(core); + executor.setMaxPoolSize(core * 2); + executor.setQueueCapacity(threadPoolProperties.getQueueCapacity()); + executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds()); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } + /** * 执行周期性或定时任务 */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/properties/ThreadPoolProperties.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/properties/ThreadPoolProperties.java new file mode 100644 index 0000000..d7f4678 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/config/properties/ThreadPoolProperties.java @@ -0,0 +1,30 @@ +package com.ruoyi.common.core.config.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 线程池 配置属性 + * + * @author Lion Li + */ +@Data +@ConfigurationProperties(prefix = "thread-pool") +public class ThreadPoolProperties { + + /** + * 是否开启线程池 + */ + private boolean enabled; + + /** + * 队列最大长度 + */ + private int queueCapacity; + + /** + * 线程池维护线程所允许的空闲时间 + */ + private int keepAliveSeconds; + +}