Skip to content

Multi-threaded Step job hangs if @StepScope bean cannot be created #3948

Open
@farnetto

Description

@farnetto

If in a multi-threaded step a @StepScope bean cannot be created then the batch just hangs waiting in TaskExecutorRepeatTemplate#waitForResults L172.

In my batch I want to pass in the pool size as a job parameter to the TaskExecutor used in the step. If this parameter is missing or cannot be converted into an int, then an exception is added to the deferred list but the TaskExecutorRepeatTemplate thinks a result is still coming from the ResultQueueResultHolder.

Here is my task executor:

@Bean
@StepScope
public TaskExecutor taskExecutor(@Value("#{jobParameters['poolSize']}") int poolSize) {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(poolSize);
	executor.setMaxPoolSize(poolSize);
	return executor;
}

Here's a pull request demonstrating the problem:

Apress/def-guide-spring-batch#13

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions