AsyncConfigurer.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package org.springblade.common.utils;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.scheduling.annotation.EnableAsync;
  6. import java.util.concurrent.*;
  7. @Slf4j
  8. @Configuration
  9. @EnableAsync
  10. public class AsyncConfigurer {
  11. /**
  12. * cpu 核心数量
  13. */
  14. public static final int cpuNum = 2 ;//Runtime.getRuntime().availableProcessors();
  15. /**
  16. * 线程池配置
  17. * @return
  18. */
  19. @Bean("taskExecutor1")
  20. public ThreadPoolExecutor getAsyncExecutor() {
  21. return new ThreadPoolMonitor(cpuNum
  22. , 10
  23. , 180
  24. , TimeUnit.SECONDS
  25. , new LinkedBlockingQueue<>(2000)
  26. , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
  27. }
  28. /**
  29. * 线程池配置
  30. *
  31. * @return
  32. */
  33. /*@Bean("singleExecutor")
  34. public ExecutorService getSingleExecutor() {
  35. log.info("线程池初始化......");
  36. return Executors.newSingleThreadExecutor();
  37. }*/
  38. }