Spring Boot Batch - Parallel Processing (Running Multiple Jobs Concurrently)
If you are new to Spring batch please check the earlier post about Spring batch introduction
In this post we will see Spring boot batch example, Spring boot batch parallel processing example
- Spring boot batch parallel processing allows multiple batch jobs to run in parallel to minimize the total elapsed batch processing time.
- This is not a problem as long as the jobs are not sharing the same files, db-tables, or index spaces. If they do, this service should be implemented using partitioned data.
We will create the application having the following 2 jobs -
- 1st Job: Reads the Product information from the database and after processing will give the rating to the project.
- 2nd Job: Reads the Invoice the information the database and update back to the database.
We are not focusing on the business logic here but the processing of data using multiple jobs.
Technical Details -
- Java 8
- Spring Boot 2.x
- Spring Batch 4.x
- MySql 5.7.17
- IntelliJ-Community Edition 2018-3 (Same code will work in Eclipse as well 😃
Source Code available on GitHub -
Project Structure -
- InvoiceProcessingJob and ProductProcessingJob these are 2 jobs having their own ItemReader, ItemProcessor, and ItemWriter.
- JobLauncherConfig will run both the above job
pom.xml Following are the dependencies -
application.propeties -
By default Spring batch is enabled, it means that as soon as application started, job will launch
We are invoking our job using scheduler that why we have provided spring.batch.job.enabled=false
Job-1: We have created the job. Notice the various annotations we are using here. @Configuration required to inform Spring container this is a Config file and will hold bean definitions.
@EnableBatchProcessing - Enables the batch processing.
Chunk Size - Denotes the commit interval. After processing 5 records job will commit the transaction
Job-2: This job reads the product information from the database and generates the invoices

Finaly Job Launcher -
Finally following is the main class to start our Spring Boot batch application -
simply awesome..keep it up 😃
ReplyDeleteThis doesn't run parallel. If i create a asynchronous job launcher it do run parallel, but my job gets executed twice. Any idea?
ReplyDelete