SpringBoot中引入多线程

@Async("threadPoolTaskExecutor")
public List<GetPayProjectListVo> getPrivateProject(Page page, DeliveryStatisticSqueryDto dto) {
  return pmProjectInfoMapper.getPrivateProjectList(page, dto, system, activiti, oa);
}

@Resource

private ThreadPoolTaskExecutor threadPoolTaskExecutor;

@PostConstruct
public void init() {
  ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor();
  threadPoolTaskExecutor.setCorePoolSize(4);
  threadPoolTaskExecutor.setKeepAliveSeconds(10);
  threadPoolTaskExecutor.setMaxPoolSize(10);
  threadPoolTaskExecutor.setQueueCapacity(10);
  threadPoolTaskExecutor.setThreadNamePrefix("task %d");
  threadPoolTaskExecutor.initialize();
}

posted @ 2023-03-30 16:13  gaoze  阅读(27)  评论(0)    收藏  举报