Revert "web容器从undertow切换到tomcat,更好地支持虚拟线程"

This reverts commit 9c8de8afbf.
This commit is contained in:
dataprince 2024-01-14 10:22:02 +08:00
parent 9c8de8afbf
commit c39403a0d2
6 changed files with 60 additions and 6 deletions

View File

@ -44,7 +44,7 @@
<mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version> <mapstruct-plus.lombok.version>0.2.0</mapstruct-plus.lombok.version>
<hutool.version>5.8.24</hutool.version> <hutool.version>5.8.24</hutool.version>
<redisson.version>3.25.2</redisson.version> <redisson.version>3.25.2</redisson.version>
<lock4j.version>2.2.7</lock4j.version> <lock4j.version>2.2.4</lock4j.version>
<alibaba-ttl.version>2.14.4</alibaba-ttl.version> <alibaba-ttl.version>2.14.4</alibaba-ttl.version>
<spring-boot-admin.version>3.2.0</spring-boot-admin.version> <spring-boot-admin.version>3.2.0</spring-boot-admin.version>
<powerjob.version>4.3.6</powerjob.version> <powerjob.version>4.3.6</powerjob.version>

View File

@ -245,6 +245,15 @@ xss:
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*,/demo/* urlPatterns: /system/*,/monitor/*,/tool/*,/demo/*
# 全局线程池相关配置
thread-pool:
# 是否开启线程池
enabled: false
# 队列最大长度
queueCapacity: 128
# 线程池维护线程所允许的空闲时间
keepAliveSeconds: 300
# 分布式锁 lock4j 全局配置 # 分布式锁 lock4j 全局配置
lock4j: lock4j:
# 获取分布式锁超时时间,默认为 3000 毫秒 # 获取分布式锁超时时间,默认为 3000 毫秒

View File

@ -2,7 +2,6 @@ package com.ruoyi.common.core.config;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
/** /**
* 程序注解配置 * 程序注解配置
@ -12,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@AutoConfiguration @AutoConfiguration
// 表示通过aop框架暴露该代理对象,AopContext能够访问 // 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true) @EnableAspectJAutoProxy(exposeProxy = true)
@EnableAsync(proxyTargetClass = true) // 指定要扫描的Mapper类的包的路径
public class ApplicationConfig public class ApplicationConfig
{ {

View File

@ -5,8 +5,8 @@ import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.SpringUtils;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -14,10 +14,9 @@ import java.util.concurrent.Executor;
/** /**
* 异步配置 * 异步配置
* *
* 如果未使用虚拟线程则生效
* @author Lion Li * @author Lion Li
*/ */
@ConditionalOnProperty(prefix = "spring.threads.virtual", name = "enabled", havingValue = "false") @EnableAsync(proxyTargetClass = true)
@AutoConfiguration @AutoConfiguration
public class AsyncConfig implements AsyncConfigurer { public class AsyncConfig implements AsyncConfigurer {

View File

@ -1,11 +1,15 @@
package com.ruoyi.common.core.config; package com.ruoyi.common.core.config;
import com.ruoyi.common.core.config.properties.ThreadPoolProperties;
import com.ruoyi.common.core.utils.Threads; import com.ruoyi.common.core.utils.Threads;
import jakarta.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration; 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.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -17,6 +21,7 @@ import java.util.concurrent.ThreadPoolExecutor;
**/ **/
@Slf4j @Slf4j
@AutoConfiguration @AutoConfiguration
@EnableConfigurationProperties(ThreadPoolProperties.class)
public class ThreadPoolConfig public class ThreadPoolConfig
{ {
/** /**
@ -26,6 +31,18 @@ public class ThreadPoolConfig
private ScheduledExecutorService scheduledExecutorService; 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;
}
/** /**
* 执行周期性或定时任务 * 执行周期性或定时任务
*/ */

View File

@ -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;
}