parent
2250cb1137
commit
ee3036e477
3 changed files with 69 additions and 0 deletions
@ -0,0 +1,54 @@ |
|||||||
|
package org.jeecg.modules.system.config; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
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.ThreadPoolExecutor; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @Description: TODO |
||||||
|
* @Author: Z.H.C |
||||||
|
* @CreateTime: 2024-11-23 16:52 |
||||||
|
* @Version: 1.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
@Configuration |
||||||
|
@EnableAsync |
||||||
|
public class AsyncExecutor { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AsyncExecutor.class); |
||||||
|
|
||||||
|
//核心线程数
|
||||||
|
private static final int CORE_POOL_SIZE = 5; |
||||||
|
|
||||||
|
//最大线程数
|
||||||
|
private static final int MAX_POOL_SIZE = 5; |
||||||
|
|
||||||
|
//队列大小
|
||||||
|
private static final int QUEUE_CAPACITY = 30; |
||||||
|
|
||||||
|
//线程池中的线程的名称前缀
|
||||||
|
private static final String THREAD_NAME = "MyExecutor-"; |
||||||
|
|
||||||
|
@Bean |
||||||
|
public ThreadPoolTaskExecutor getAsyncExecutorMethod() { |
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
||||||
|
//配置核心线程数
|
||||||
|
executor.setCorePoolSize(CORE_POOL_SIZE); |
||||||
|
//配置最大线程数
|
||||||
|
executor.setMaxPoolSize(MAX_POOL_SIZE); |
||||||
|
//配置队列大小
|
||||||
|
executor.setQueueCapacity(QUEUE_CAPACITY); |
||||||
|
//配置线程池中的线程的名称前缀
|
||||||
|
executor.setThreadNamePrefix(THREAD_NAME); |
||||||
|
//配置线程池拒绝策略,我设置为CallerRunsPolicy,当线程和队列都满了,由发起线程的主线程自己执行
|
||||||
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
||||||
|
executor.initialize(); |
||||||
|
return executor; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue