Мой сервис:
Код: Выделить всё
@Async
public List doSomething(int a){
//Do something
return list;
}
Код: Выделить всё
@SpringBootApplication
@EnableAsync
public class Test {
public static void main(String[] args) {
SpringApplication.run(Test.class, args);
}
}
Код: Выделить всё
@Configuration
@EnableAsync
public class AsyncConfig {
@Bean(name ="taskExecutor")
public Executor taskExecutor(){
ThreadPoolTaskExecutor executor=new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("userThread-");
executor.initialize();
return executor;
}
}
Код: Выделить всё
@RestController
public class Controller{
@Autowired
private Service service;
@GetMapping("test")
public List getAll(){
return service.doSomething(1);
}
}
Подробнее здесь: https://stackoverflow.com/questions/718 ... ction-call
Мобильная версия