Skip to content

Make TaskExecutor of SimpleJobLauncher configurable via BasicBatchConfigurer #27899

Closed
@aahlenst

Description

@aahlenst

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.

protected JobLauncher createJobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(getJobRepository());
jobLauncher.afterPropertiesSet();
return jobLauncher;
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions