@Configuration
@EnableAsync
public class AsyncConfig {
@Bean
public Executor taskExecutor(){
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(1);
threadPoolTaskExecutor.setQueueCapacity(50);
threadPoolTaskExecutor.setMaxPoolSize(10);
return threadPoolTaskExecutor;
}
}
@Controller
public class AsyncController{
@Autowired
private AsyncService asyncService;
@GetMapping("/test")
public String test(){
Future<Void> task = asyncService.test();
return "test";
}
}
@Service
public class AsyncService{
@Async("taskExecutor")
public void test(){
System.out.println("test");
}
}