Browse Source

线程池数调整

master
luogw 1 month ago
parent
commit
91e8eb21da
  1. 2
      src/main/java/com/project/ding/utils/DingUtil.java
  2. 2
      src/main/java/com/project/information/application/KnowledgePointApplicationServiceImpl.java
  3. 41
      src/main/java/com/project/information/config/InformationAsyncConfig.java
  4. 6
      src/main/java/com/project/information/mapper/KnowledgePointMapper.java
  5. 2
      src/main/java/com/project/operation/application/OperationLogApplicationServiceImpl.java
  6. 37
      src/main/java/com/project/operation/config/AsyncConfig.java

2
src/main/java/com/project/ding/utils/DingUtil.java

@ -141,7 +141,7 @@ public class DingUtil {
/** /**
* 发送工作通知 * 发送工作通知
*/ */
@Async("dingNoticeExecutor") @Async("asycExecutor")
public void sendWorkNotice(AppealDTO appealDTO) throws DtErrorException { public void sendWorkNotice(AppealDTO appealDTO) throws DtErrorException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String nowTime = LocalDateTime.now().format(formatter); String nowTime = LocalDateTime.now().format(formatter);

2
src/main/java/com/project/information/application/KnowledgePointApplicationServiceImpl.java

@ -51,7 +51,7 @@ public class KnowledgePointApplicationServiceImpl implements KnowledgePointAppli
} }
@Override @Override
@Async("parseExecutor") @Async("asycExecutor")
public void parse(Map<Long, MultipartFile> fileMap) { public void parse(Map<Long, MultipartFile> fileMap) {
for (Long id : fileMap.keySet()) { for (Long id : fileMap.keySet()) {
try { try {

41
src/main/java/com/project/information/config/InformationAsyncConfig.java

@ -1,41 +0,0 @@
package com.project.information.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 异步配置类开启异步支持
*/
@Configuration
@EnableAsync
public class InformationAsyncConfig {
/**
* 自定义发生通知异步线程池
*/
@Bean(name = "parseExecutor")
public Executor parseExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数(根据业务量调整)
executor.setCorePoolSize(5);
// 最大线程数
executor.setMaxPoolSize(10);
// 队列容量
executor.setQueueCapacity(100);
// 线程前缀名(便于日志排查)
executor.setThreadNamePrefix("parse-file-");
// 线程空闲超时时间
executor.setKeepAliveSeconds(60);
// 拒绝策略:队列满时由调用线程执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化线程池
executor.initialize();
return executor;
}
}

6
src/main/java/com/project/information/mapper/KnowledgePointMapper.java

@ -19,9 +19,9 @@ public interface KnowledgePointMapper extends BaseMapper<KnowledgePointEntity> {
*/ */
@Select({ @Select({
"SELECT", "SELECT",
" SUM(CASE WHEN p.knowledgeType = 0 THEN 1 ELSE 0 END) AS preciseSum,", " SUM(CASE WHEN p.knowledge_type = 0 THEN 1 ELSE 0 END) AS preciseSum,",
" SUM(CASE WHEN p.knowledgeType = 1 THEN 1 ELSE 0 END) AS blurSum", " SUM(CASE WHEN p.knowledge_type = 1 THEN 1 ELSE 0 END) AS blurSum",
"FROM evaluator_knowledge_point e", "FROM evaluator_information e",
"INNER JOIN evaluator_knowledge_point p ON p.information_id = e.id", "INNER JOIN evaluator_knowledge_point p ON p.information_id = e.id",
"WHERE e.sub_line_id = #{subLineId}" "WHERE e.sub_line_id = #{subLineId}"
}) })

2
src/main/java/com/project/operation/application/OperationLogApplicationServiceImpl.java

@ -36,7 +36,7 @@ public class OperationLogApplicationServiceImpl implements OperationLogApplicati
} }
@Override @Override
@Async("operationLogExecutor") @Async("asycExecutor")
public void saveOperationLogAsync(OperationLogDTO operationLogDTO) { public void saveOperationLogAsync(OperationLogDTO operationLogDTO) {
this.saveOperationLog(operationLogDTO); this.saveOperationLog(operationLogDTO);
} }

37
src/main/java/com/project/operation/config/AsyncConfig.java

@ -16,19 +16,19 @@ import java.util.concurrent.ThreadPoolExecutor;
public class AsyncConfig { public class AsyncConfig {
/** /**
* 自定义日志异步线程池 * 自定义异步线程池
*/ */
@Bean(name = "operationLogExecutor") @Bean(name = "asycExecutor")
public Executor operationLogExecutor() { public Executor asycExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数(根据业务量调整) // 核心线程数
executor.setCorePoolSize(5); executor.setCorePoolSize(2);
// 最大线程数 // 最大线程数
executor.setMaxPoolSize(20); executor.setMaxPoolSize(5);
// 队列容量 // 队列容量
executor.setQueueCapacity(100); executor.setQueueCapacity(100);
// 线程前缀名(便于日志排查) // 线程前缀名(便于日志排查)
executor.setThreadNamePrefix("operation-log-"); executor.setThreadNamePrefix("asyc-log-");
// 线程空闲超时时间 // 线程空闲超时时间
executor.setKeepAliveSeconds(60); executor.setKeepAliveSeconds(60);
// 拒绝策略:队列满时由调用线程执行(避免日志丢失) // 拒绝策略:队列满时由调用线程执行(避免日志丢失)
@ -37,27 +37,4 @@ public class AsyncConfig {
executor.initialize(); executor.initialize();
return executor; return executor;
} }
/**
* 自定义日志异步线程池
*/
@Bean(name = "dingNoticeExecutor")
public Executor dingNoticeExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数(根据业务量调整)
executor.setCorePoolSize(5);
// 最大线程数
executor.setMaxPoolSize(20);
// 队列容量
executor.setQueueCapacity(100);
// 线程前缀名(便于日志排查)
executor.setThreadNamePrefix("ding-notice-");
// 线程空闲超时时间
executor.setKeepAliveSeconds(60);
// 拒绝策略:队列满时由调用线程执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化线程池
executor.initialize();
return executor;
}
} }

Loading…
Cancel
Save