【发布时间】:2019-12-16 13:22:22
【问题描述】:
我现在使用@EnableAsync 和@Async 注解在Spring Boot 中使用多线程。我有服务 A(快)和服务 B(慢)。
如何为他们设置不同的池?因此,当对 B 的调用很多时,应用程序仍然可以在与 B 不同的池中处理服务 A。
@Configuration
@EnableAsync
public class ServiceExecutorConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(30);
taskExecutor.setMaxPoolSize(40);
taskExecutor.setQueueCapacity(10);
taskExecutor.initialize();
return taskExecutor;
}
}
【问题讨论】:
标签: java spring multithreading spring-boot threadpoolexecutor