54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
package com.imyeyu.api.config;
|
|
|
|
import lombok.Data;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
/**
|
|
* 线程池配置
|
|
*
|
|
* @author 夜雨
|
|
* @since 2023-08-21 16:31
|
|
*/
|
|
@Data
|
|
@Slf4j
|
|
@Configuration
|
|
public class ThreadPoolConfig {
|
|
|
|
@Bean(name = "threadPoolTaskExecutor")
|
|
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
executor.setCorePoolSize(16);
|
|
executor.setMaxPoolSize(32);
|
|
executor.setQueueCapacity(16);
|
|
executor.setKeepAliveSeconds(60);
|
|
executor.setAwaitTerminationSeconds(60);
|
|
executor.setThreadNamePrefix("thread-pool-task-executor-");
|
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
|
|
/// 创建操作审计线程池
|
|
///
|
|
/// @return 操作审计线程池
|
|
@Bean(name = "auditTaskExecutor")
|
|
public ThreadPoolTaskExecutor auditTaskExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
executor.setCorePoolSize(4);
|
|
executor.setMaxPoolSize(8);
|
|
executor.setQueueCapacity(2000);
|
|
executor.setKeepAliveSeconds(60);
|
|
executor.setWaitForTasksToCompleteOnShutdown(true);
|
|
executor.setAwaitTerminationSeconds(60);
|
|
executor.setThreadNamePrefix("audit-task-executor-");
|
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
}
|