DEV Community

loizenai
loizenai

Posted on

Spring Batch Job with Parallel Steps

https://grokonez.com/spring-framework/spring-batch/spring-batch-job-parallel-steps

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:

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

<?xml version="1.0" encoding="UTF-8"?>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>  
    
      <dependency>
           <groupId>mysql</groupId>
           <artifactId>mysql-connector-java</artifactId>
           <scope>runtime</scope>
       </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>                              
</dependencies>

3. Config Batch Job DataSource

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


spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=12345
spring.batch.job.enabled=false

https://grokonez.com/spring-framework/spring-batch/spring-batch-job-parallel-steps

Spring Batch Job with Parallel Steps

Top comments (0)