AsyncConfigurer.java 876 B

12345678910111213141516171819202122232425262728293031323334
  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 = 1 ;//Runtime.getRuntime().availableProcessors();
  15. /**
  16. * 线程池配置
  17. * @return
  18. */
  19. @Bean("taskExecutor1")
  20. public ThreadPoolExecutor getAsyncExecutor() {
  21. return new ThreadPoolMonitor(cpuNum
  22. , 15
  23. , 180
  24. , TimeUnit.SECONDS
  25. , new LinkedBlockingQueue<>(2000)
  26. , new ThreadPoolExecutor.DiscardOldestPolicy(), "manager-thread-pool");
  27. }
  28. }