From ee632a69cdd218b382e42fc4ccb6ac7cf34c1dde Mon Sep 17 00:00:00 2001 From: liyongde <1419499670@qq.com> Date: Fri, 5 Jan 2024 14:09:39 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E7=BA=BF=E7=A8=8B=E3=80=81tomcat?= =?UTF-8?q?=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lms/nladmin-system/pom.xml | 5 +++ .../src/main/java/org/nl/AppRun.java | 2 + .../config/thread/ThreadPoolExecutorUtil.java | 23 ++++++++--- .../service/quartz/utils/ExecutionJob.java | 6 ++- .../src/main/resources/config/application.yml | 38 +++++++++++++++++++ 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/lms/nladmin-system/pom.xml b/lms/nladmin-system/pom.xml index c4070f154..40e0cbdef 100644 --- a/lms/nladmin-system/pom.xml +++ b/lms/nladmin-system/pom.xml @@ -31,6 +31,11 @@ + + org.dromara.dynamictp + dynamic-tp-spring-boot-starter-adapter-webserver + 1.1.6.1 + com.yomahub diff --git a/lms/nladmin-system/src/main/java/org/nl/AppRun.java b/lms/nladmin-system/src/main/java/org/nl/AppRun.java index 8f8e5ba91..82688bca3 100644 --- a/lms/nladmin-system/src/main/java/org/nl/AppRun.java +++ b/lms/nladmin-system/src/main/java/org/nl/AppRun.java @@ -3,6 +3,7 @@ package org.nl; import cn.dev33.satoken.annotation.SaIgnore; import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation; import com.alicp.jetcache.anno.config.EnableMethodCache; +import org.dromara.dynamictp.core.spring.EnableDynamicTp; import org.mybatis.spring.annotation.MapperScan; import org.nl.modules.wql.util.SpringContextHolder; import org.springframework.boot.SpringApplication; @@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; */ @EnableAsync @RestController +@EnableDynamicTp @SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class }) diff --git a/lms/nladmin-system/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java b/lms/nladmin-system/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java index 08e8dfa4b..14ed1dcd8 100644 --- a/lms/nladmin-system/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java +++ b/lms/nladmin-system/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java @@ -16,7 +16,12 @@ package org.nl.config.thread; +import org.dromara.dynamictp.core.support.DynamicTp; import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -28,16 +33,22 @@ import java.util.concurrent.TimeUnit; * @author Zheng Jie * @date 2019年10月31日18:16:47 */ +@Configuration public class ThreadPoolExecutorUtil { - public static ThreadPoolExecutor getPoll() { - AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class); + @Autowired + private AsyncTaskProperties asyncTaskProperties; + + @Bean + @Primary + @DynamicTp("el-thread") + public ThreadPoolExecutor threadPoolExecutor() { return new ThreadPoolExecutor( - properties.getCorePoolSize(), - properties.getMaxPoolSize(), - properties.getKeepAliveSeconds(), + asyncTaskProperties.getCorePoolSize(), + asyncTaskProperties.getMaxPoolSize(), + asyncTaskProperties.getKeepAliveSeconds(), TimeUnit.SECONDS, - new ArrayBlockingQueue<>(properties.getQueueCapacity()), + new ArrayBlockingQueue<>(asyncTaskProperties.getQueueCapacity()), new TheadFactoryName() ); } diff --git a/lms/nladmin-system/src/main/java/org/nl/system/service/quartz/utils/ExecutionJob.java b/lms/nladmin-system/src/main/java/org/nl/system/service/quartz/utils/ExecutionJob.java index b1c551c88..5f2628b56 100644 --- a/lms/nladmin-system/src/main/java/org/nl/system/service/quartz/utils/ExecutionJob.java +++ b/lms/nladmin-system/src/main/java/org/nl/system/service/quartz/utils/ExecutionJob.java @@ -16,6 +16,8 @@ import org.nl.system.service.quartz.impl.SysQuartzJobServiceImpl; import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.scheduling.annotation.Async; import java.util.concurrent.Future; @@ -35,7 +37,9 @@ public class ExecutionJob extends TLogQuartzJobBean { /** * 该处仅供参考 */ - private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll(); + @Autowired + @Qualifier("threadPoolExecutor") + private ThreadPoolExecutor EXECUTOR; @Override public void executeTask(JobExecutionContext context) throws JobExecutionException { diff --git a/lms/nladmin-system/src/main/resources/config/application.yml b/lms/nladmin-system/src/main/resources/config/application.yml index de3865a29..c5e679827 100644 --- a/lms/nladmin-system/src/main/resources/config/application.yml +++ b/lms/nladmin-system/src/main/resources/config/application.yml @@ -13,7 +13,45 @@ spring: redis: repositories: enabled: false + dynamic: + tp: + enabled: true # 是否启用 dynamictp,默认true + enabledBanner: false # 是否启用 控制台banner,默认true + enabledCollect: true # 是否开启监控指标采集,默认true + collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer + logPath: C:\log\lms # 监控日志数据路径,默认 ${user.home}/logs,采集类型非logging不用配置 + monitorInterval: 8 + tomcatTp: # tomcat webserver 线程池配置 + threadPoolAliasName: tomcat 线程池 # 线程池别名,可选 + corePoolSize: 100 + maximumPoolSize: 200 + keepAliveTime: 60 + runTimeout: 10000 + queueTimeout: 100 + notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警) + - type: change + enabled: true + - type: capacity # 队列容量使用率,报警项类型,查看源码 NotifyTypeEnum枚举类 + enabled: true + threshold: 80 # 报警阈值,默认70,意思是队列使用率达到70%告警 + interval: 120 # 报警间隔(单位:s),默认120 + + - type: liveness # 线程池活性 + enabled: true + threshold: 80 # 报警阈值,默认 70,意思是活性达到70%告警 + + - type: reject # 触发任务拒绝告警 + enabled: true + threshold: 100 # 默认阈值10 + + - type: run_timeout # 任务执行超时告警 + enabled: true + threshold: 100 # 默认阈值10 + + - type: queue_timeout # 任务排队超时告警 + enabled: true + threshold: 100 # 默认阈值10 #配置 Jpa jpa: hibernate: