12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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 =2 ;//Runtime.getRuntime().availableProcessors();
- /**
- * 线程池配置
- *
- * @return
- */
- @Bean("taskExecutor1")
- public ThreadPoolExecutor getAsyncExecutor() {
- return new ThreadPoolMonitor(cpuNum
- , 4
- , 30
- , TimeUnit.SECONDS
- , new LinkedBlockingQueue<>(2000)
- , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
- }
- /**
- * 线程池配置
- *
- * @return
- */
- /*@Bean("singleExecutor")
- public ExecutorService getSingleExecutor() {
- log.info("线程池初始化......");
- return Executors.newSingleThreadExecutor();
- }*/
- }
|