content: package com.cf.pay.service.config;
  
  import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.scheduling.annotation.AsyncConfigurer;
  import org.springframework.scheduling.annotation.EnableScheduling;
  import org.springframework.scheduling.annotation.SchedulingConfigurer;
  import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
  import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  
  import java.util.concurrent.Executor;
  
  /**
   * @author Administrator
   * @version 1.0
   **/
  @Configuration
  @EnableScheduling
  public class AsyncTaskConfig implements SchedulingConfigurer, AsyncConfigurer {
      //线程池线程数量
      private int corePoolSize = 5;
  
      @Bean
      public ThreadPoolTaskScheduler taskScheduler()
      {
          ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
          scheduler.initialize();//初始化线程池
          scheduler.setPoolSize(corePoolSize);//线程池容量
          return scheduler;
      }
  
      @Override
      public Executor getAsyncExecutor() {
          Executor executor = taskScheduler();
          return executor;
      }
  
      @Override
      public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
          return null;
      }
  
      @Override
      public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
          scheduledTaskRegistrar.setTaskScheduler(taskScheduler());
      }
  }
  