AsyncConfigurer.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. *
  18. * @return
  19. */
  20. @Bean("taskExecutor1")
  21. public ThreadPoolExecutor getAsyncExecutor() {
  22. return new ThreadPoolMonitor(cpuNum
  23. , 4
  24. , 30
  25. , TimeUnit.SECONDS
  26. , new LinkedBlockingQueue<>(2000)
  27. , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
  28. }
  29. /**
  30. * 线程池配置
  31. *
  32. * @return
  33. */
  34. /*@Bean("singleExecutor")
  35. public ExecutorService getSingleExecutor() {
  36. log.info("线程池初始化......");
  37. return Executors.newSingleThreadExecutor();
  38. }*/
  39. }