ThreadPoolTask​​Executor执行5个并行请求,每个请求有50个线程

时间:2020-11-06 13:17:21

标签: java spring multithreading spring-boot rest

我在ThreadPoolTask​​Executor中具有以下代码。当我一次发送100个请求时,它正在执行所有请求。但我一次只希望5个请求。 如何实现这一目标?

@EnableAsync
@SpringBootApplication
public class GroupDepositsApplication  {

    
  @Bean(name = "processExecutor")
  public TaskExecutor workExecutor() 
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(50);
        executor.setMaxPoolSize(Integer.MAX_VALUE);
        executor.setQueueCapacity(50);
        executor.setThreadNamePrefix("MyExecutor");
        executor.initialize();
        return executor;
    }

  public static void main(String[] args) {
    SpringApplication.run(DepositApplication.class, args);
  }

}


this the method controller will be calling

@Async("processExecutor")
  public void processPendingAwardRecords(
      List<GroupEntity> pendingRecordsToProcess,
      User user) {

// data base operations......
}

0 个答案:

没有答案