Spring Batch Job with Parallel Steps

For scaling a Batch Job, Parallel Steps is one solution that bases on the business logic of application. We split the logic business in distinct responsibilities, and each step can be executed in parallelized flow. The tutorial will guide you how to configure parallel steps with Spring Batch.

Related Articles:
Spring Batch Partition for Scaling & Parallel Processing
How to start with Spring Batch using Spring Boot – Java Config

I. Technologies for spring batch parallel step tutorial

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot
– MySQL Database

II. Overview
1. Structure of project

spring batch parallel step structure-of-project

2. Step to do

– Create Spring Boot project
– Add dependencies
– Config Batch Job DataSource
– Create a Simple Tasklet Step
– Create a Job Launch
– Enable Batch Job
– Define Spring Batch Job with XML config
– Run & Check Result

III. Practices
1. Create Spring Boot project

Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, input project info. Then press Finish, spring boot project will be created.

2. Add dependencies

Add spring-boot-starter-batch, spring-boot-starter-web, mysql-connector-java

3. Config Batch Job DataSource

Open application.properties, config spring-datasource for batch job repository

4. Create a Simple Tasklet Step

Create a SimpleStep that implements the Tasklet interface.
We define a workload function for simulating the hard processing.

5. Define Spring Batch Job with XML config

Here is the main part of tutorial.

spring batch parallel step-flow-split

We defines 4 steps: step_1, step_2, step_3, step_4. Step_1, Step_2, Step_3 are designed for parallel processing with 3 flow in a split split_1.

After split_1 is Done, it means: step_1, step_2, step_3 are Done, then step_4 is processed.


The TaskExecutor is defaulted by a SyncTaskExecutor, but for parallel processing batch job requires an asynchronous TaskExecutor. So we set task-executor=”taskExecutor” with:

6. Create a Job Launch

Use a Controller for launch a Batch Job

7. Enable Batch Job

In the main class of Spring boot, annotation with @EnableBatchProcessing


8. Run & Check Result

Build project with Maven: clean install
Run project with mode: Spring Boot App

Make a launch request:


IV. Source code


Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *