I have a Spring Boot application which is responsible for answering requests via REST. I also push metrics about my application call. Since this is a separate task and I have to response users immediately, I want to make that metrics publishing asynchronously. So I've used that:
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("MyApp-");
executor.initialize();
return executor;
However, this one uses SimpleAsyncTaskExecutor and does not reuse any threads.
1) How can I use ConcurrentTaskExecutor instead of SimpleAsyncTaskExecutor?
2) Which implementation could best fit for my needs?
ThreadPoolTaskExecutordoes not useSimpleAsyncTaskExecutor, it uses Java's standardThreadPoolExecutor(see the implementation). So you are already sort of using theConcurrentTaskExecutor.