12345678910111213141516171819202122232425262728293031323334 |
- package org.springblade.common.utils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.EnableAsync;
- import java.util.concurrent.*;
- @Slf4j
- @Configuration
- @EnableAsync
- public class AsyncConfigurer {
- /**
- * cpu 核心数量
- */
- public static final int cpuNum = 1 ;//Runtime.getRuntime().availableProcessors();
- /**
- * 线程池配置
- * @return
- */
- @Bean("taskExecutor1")
- public ThreadPoolExecutor getAsyncExecutor() {
- return new ThreadPoolMonitor(cpuNum
- , 15
- , 180
- , TimeUnit.SECONDS
- , new LinkedBlockingQueue<>(2000)
- , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
- }
- }
|