Mein Service:
Code: Select all
@Async
public List doSomething(int a){
//Do something
return list;
}
Code: Select all
@SpringBootApplication
@EnableAsync
public class Test {
public static void main(String[] args) {
SpringApplication.run(Test.class, args);
}
}
Code: Select all
@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;
}
}
Code: Select all
@RestController
public class Controller{
@Autowired
private Service service;
@GetMapping("test")
public List getAll(){
return service.doSomething(1);
}
}