572 lines
24 KiB
Java
Raw Normal View History

2024-03-26 19:06:41 +08:00
package com.zhgd.xmgl.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
2024-05-14 16:03:54 +08:00
import org.springframework.security.core.context.SecurityContextHolder;
2024-03-26 19:06:41 +08:00
2024-05-20 16:04:50 +08:00
import javax.annotation.PostConstruct;
2024-03-26 19:06:41 +08:00
import java.util.concurrent.ThreadPoolExecutor;
/**
* @program: wisdomSite
* @description: 线程池配置
* @author: Mr.Peng
* @create: 2021-02-23 10:04
**/
@Configuration
public class AsyncConfig {
/**
* Set the ThreadPoolExecutor's core pool size.
*/
private int corePoolSize = 8;
/**
* Set the ThreadPoolExecutor's maximum pool size.
*/
private int maxPoolSize = 16;
/**
* Set the capacity for the ThreadPoolExecutor's BlockingQueue.
*/
private int queueCapacity = 200;
2024-05-20 16:04:50 +08:00
@PostConstruct
public void init() {
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
2024-05-14 16:03:54 +08:00
}
2024-03-26 19:06:41 +08:00
/**
* 默认情况下在创建了线程池后线程池中的线程数为0当有任务来之后就会创建一个线程去执行任务
* 当线程池中的线程数目达到corePoolSize后就会把到达的任务放到缓存队列当中
* 当队列满了就继续创建线程当线程数量大于等于maxPoolSize后开始使用拒绝策略拒绝
*/
@Primary
@Bean("taskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("taskExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
/**
* 默认情况下在创建了线程池后线程池中的线程数为0当有任务来之后就会创建一个线程去执行任务
* 当线程池中的线程数目达到corePoolSize后就会把到达的任务放到缓存队列当中
* 当队列满了就继续创建线程当线程数量大于等于maxPoolSize后开始使用拒绝策略拒绝
*/
@Bean("doubleCarbonExecutor")
public ThreadPoolTaskExecutor doubleCarbonExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("doubleCarbonExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("countAttendanceExecutor")
public ThreadPoolTaskExecutor attendanceExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("countAttendanceExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("sendAttendanceExecutor")
public ThreadPoolTaskExecutor sendAttendanceExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("sendAttendanceExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("sendWorkerExecutor")
public ThreadPoolTaskExecutor sendWorkerExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
2024-06-15 22:19:09 +08:00
executor.setCorePoolSize(corePoolSize);
2024-03-26 19:06:41 +08:00
/** 最大线程数 */
2024-06-15 22:19:09 +08:00
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
2024-03-26 19:06:41 +08:00
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("sendWorkerExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("sendExitWorkerExecutor")
public ThreadPoolTaskExecutor sendExitWorkerExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("sendExitWorkerExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("environmentNoiseDataExecutor")
public ThreadPoolTaskExecutor sendEnvironmentNoiseDataExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("environmentNoiseDataExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("electricalExecutor")
public ThreadPoolTaskExecutor sendElectricalExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("electricalExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("towerExecutor")
public ThreadPoolTaskExecutor sendTowerExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("towerExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("lifterExecutor")
public ThreadPoolTaskExecutor sendLifterExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("lifterExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("devExcavationExecutor")
public ThreadPoolTaskExecutor sendDevExcavationEExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("devExcavationExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("gantryCraneExecutor")
public ThreadPoolTaskExecutor sendGantryCraneExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("gantryCraneExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("fileExecutor")
public ThreadPoolTaskExecutor fileExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("fileExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("asyncExecutor")
public ThreadPoolTaskExecutor asyncExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("asyncExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Primary
@Bean("bimExecutor")
public ThreadPoolTaskExecutor bimExecutor() {
2024-06-12 21:55:13 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-03-26 19:06:41 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(2000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("bimExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-04-27 17:51:47 +08:00
2024-06-14 09:10:46 +08:00
/**
* 单个线程
*
* @return
*/
2024-04-27 17:51:47 +08:00
@Bean("hikvisionExecutor")
public ThreadPoolTaskExecutor hikvisionExecutor() {
2024-05-20 10:01:23 +08:00
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-04-27 17:51:47 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(1);
/** 最大线程数 */
executor.setMaxPoolSize(1);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
2024-04-27 17:51:47 +08:00
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("sendWorkerExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-05-05 17:59:06 +08:00
@Bean("carInfoExecutor")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor carInfoExecutor() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-05-05 17:59:06 +08:00
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(100000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("carInfoExecutor-");
// 线程池对拒绝任务的处理策略
2024-05-31 18:47:42 +08:00
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
2024-05-05 17:59:06 +08:00
// 初始化
executor.initialize();
return executor;
}
@Bean("getCrossRecords")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor getCrossRecords() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("getCrossRecords-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("getDoorEvents")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor getDoorEvents() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("getDoorEvents-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("saveEventCallbackAttendance")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor saveEventCallbackAttendance() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("saveEventCallbackAttendance-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("saveEventCallbackCarPassRecord")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor saveEventCallbackCarPassRecord() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("saveEventCallbackCarPassRecord-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("saveEventCallbackAiAsync")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor saveEventCallbackAiAsync() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
2024-05-31 18:47:42 +08:00
executor.setCorePoolSize(corePoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("saveEventCallbackAiAsync-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-05-17 16:28:20 +08:00
@Bean("getRecordForHikvisionTask")
2024-05-20 10:05:09 +08:00
public MdcThreadPoolTaskExecutor getRecordForHikvisionTask() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
2024-05-17 16:28:20 +08:00
/** 核心线程数(默认线程数) */
2024-05-31 18:47:42 +08:00
executor.setCorePoolSize(1);
2024-05-17 16:28:20 +08:00
/** 最大线程数 */
executor.setMaxPoolSize(160);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(1000);
2024-05-17 16:28:20 +08:00
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("getRecordForHikvisionTask-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-05-31 18:47:42 +08:00
@Bean("syncXzHikvisionCompareData")
public MdcThreadPoolTaskExecutor syncXzHikvisionCompareData() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
2024-06-01 23:53:10 +08:00
executor.setCorePoolSize(corePoolSize);
2024-05-31 18:47:42 +08:00
/** 最大线程数 */
2024-06-01 23:53:10 +08:00
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(1000);
2024-05-31 18:47:42 +08:00
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("syncXzHikvisionCompareData-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-05-05 17:59:06 +08:00
2024-06-12 23:28:31 +08:00
@Bean("sendBatchExecutor")
public ThreadPoolTaskExecutor sendBatchExecutor() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
2024-06-15 22:19:09 +08:00
executor.setCorePoolSize(maxPoolSize * 5);
2024-06-12 23:28:31 +08:00
/** 最大线程数 */
2024-06-15 22:19:09 +08:00
executor.setMaxPoolSize(maxPoolSize * 5);
2024-06-14 09:10:46 +08:00
executor.setQueueCapacity(queueCapacity * 10);
2024-06-12 23:28:31 +08:00
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("sendBatchExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-06-14 09:10:46 +08:00
2024-06-15 22:19:09 +08:00
@Bean("workerHkExecutor")
public ThreadPoolTaskExecutor workerHkExecutor() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("workerHkExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 初始化
executor.initialize();
return executor;
}
@Bean("workerAuthHkExecutor")
public ThreadPoolTaskExecutor workerAuthHkExecutor() {
MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor();
/** 核心线程数(默认线程数) */
executor.setCorePoolSize(maxPoolSize);
/** 最大线程数 */
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity * 10);
/** 允许线程空闲时间(单位:默认为秒) */
executor.setKeepAliveSeconds(60);
/** 线程池名前缀 */
executor.setThreadNamePrefix("workerAuthHkExecutor-");
// 线程池对拒绝任务的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
// 初始化
executor.initialize();
return executor;
}
2024-03-26 19:06:41 +08:00
}