Description
The auto-configuration for Spring Batch uses the SimpleJobLauncher
with SyncTaskExecutor
, which is the default. Consequently, Batch jobs are run on the same thread they are launched on, even if it is a Tomcat worker thread. I find this surprising, considering that Spring Boot typically employs sensible defaults, and I have not seen it mentioned in the docs (or in any issue). Furthermore, I expected that Spring Boot would pick up the auto-configured TaskExecutor
, but it does not.
If it was a conscious decision to use the SimpleJobLauncher
with its default task executor, it would be nice if it were documented. Ideally, the docs would also offer some guidance on properly configuring Spring Batch with a different task executor (I expect the answer is to extend BasicBatchConfigurer
and to override createJobLauncher()
) and whether it's appropriate to use the auto-configured TaskExecutor
.
Otherwise, I think it would make sense to change BasicBatchConfigurer
to either pick up the auto-configured TaskExecutor
, possibly introducing an annotation modelled after @BatchDataSource
that allows to configure a dedicated TaskExecutor
for batch jobs easily.