I have read the code but did not find the default pool type of ThreadPoolTaskExecutor. what is the default thread pool of ThreadPoolTaskExecutor? newFixedThreadPool or newCachedThreadPool?
For pure spring application , the default TaskExecutor
will be resolved in the following orders (source codes here) :
org.springframework.core.task.TaskExecutor
java.util.concurrent.Executor
and with the name
taskExecutor
SimpleAsyncTaskExecutor
So if you do not configure anything , by default it will use SimpleAsyncTaskExecutor
which internally does not use JDK 's ThreadPoolExecutor
to create a thread. So there is no thread pooling and will create a new thread for each async invocation.
For spring-boot application , it will auto-configure a ThreadPoolTaskExecutor
bean (docs) . As ThreadPoolTaskExecutor
is a type of org.springframework.core.task.TaskExecutor
, it will be used as the default according to the above mentioned order.
ThreadPoolTaskExecutor
internally use JDK 's ThreadPoolExecutor
, but neither its use newFixedThreadPool()
nor newCachedThreadPool()
to create ThreadPoolExecutor
. Rather it directly call its constructor to create but then configure its setting based on the application properties.(source codes here)