I have a REST
webservice and want to log any incoming and outgoing XML
requests.
As they can be quite large and I also have to apply some sort of transformation, I'd like to execute that in an async thread.
So far I'm just using @Async
annotation on the logger method. That will use the default SimpleAsyncTaskExecutor
, which "does not reuse any threads":
https://docs.spring.io/spring/docs/4.3.x/spring-framework-reference/htmlsingle/#scheduling-task-executor-types
Question: should I better define my own ThreadPoolTaskExecutor
rather than relying on the default simple executor? Would it be wise to have a "reusing threads" executor for the short-lived logging tasks?
Further do consider: I will also be having some async database row updates that should also be executing using @Async
, and probably with the same executor.
My main problem is: I don't want to think about a fixed pool size of threads, capacity, throttle limits etc. I just want to tell my routine: "Execute the following logic in an async thread." And just stack anything on it.
Which of the TaskExecutors
would I have to use for it, and which configuration should be applied?
Would eg the following executor fit?
@Bean
public ThreadPoolTaskExecutor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(4);
return executor;
}