| | |
| | | package org.springblade.common.config; |
| | | |
| | | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.task.TaskExecutor; |
| | | import org.springframework.scheduling.annotation.AsyncConfigurer; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | |
| | | /** |
| | |
| | | * @since 2022-02-22 |
| | | */ |
| | | @EnableAsync |
| | | public class AsyncConfig { |
| | | public class AsyncConfig{ |
| | | |
| | | @Bean |
| | | public TaskExecutor executor(){ |
| | | public Executor getAsyncExecutor() { |
| | | ThreadPoolTaskExecutor executor=new ThreadPoolTaskExecutor(); |
| | | //核心线程数 |
| | | executor.setCorePoolSize(10); |
| | | executor.setCorePoolSize(4); |
| | | //最大线程数 |
| | | executor.setMaxPoolSize(20); |
| | | executor.setMaxPoolSize(6); |
| | | //队列大小 |
| | | executor.setQueueCapacity(1000); |
| | | //线程最大空闲时间 |
| | | executor.setKeepAliveSeconds(300); |
| | | executor.setThreadNamePrefix("fsx-Executor-"); |
| | | //指定用于新创建的线程名称的前缀。 |
| | | executor.setThreadNamePrefix("fsx-Executor-"); |
| | | //设置拒绝策略 CallerRunsPolicy 由调用的线程来处理这个任务 |
| | | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | //返回 |
| | | return executor; |