Step Execution In Spring Batch

A Real Time Use case of Spring Batch

One of the most common use case in a developer’s life is the ‘Report Generation’ of high volume data, where we can apply the concept of Spring Batch. For example, let’s assume you have a report generation system, where you need to read a high volume of data from a database and write the same data in a CSV file. Here, in this scenario we can use Spring Batch to fulfil our requirements as the traditional way of generating report may not handle the high volume of data. Obviously, in this case the database will be source and CSV file will be the destination.

What are the common use cases of Spring Batch?

  1. ETL (Extract, Transform, Load)
  2. Data Migration
  3. Parallel Processing
  4. Reporting
  5. Exchange of Information

What is the Step in Spring Batch Processing?

A step is a phase in a job that defines how the actual processing will occur for that portion of the job. There are two types of steps: Tasklet-based Step and Chunk-based Step.

Tasklet-based Step

It’s interface contains a single method named ‘execute()’ that runs over and over until it gives signal to stop. Generally, we use tasklets for things like stored procedures, setup logics, or other custom logics that can’t be achieved without the box components.

Chunk-based Step

It is used in scenarios where we need to process data from a data source. In chunk-based steps, each step internally has a reader, writer and an optional processor. Spring Batch API provides interfaces: ItemReader, ItemWriter, and ItemProcessor for reader, writer and processor to implement the respective functionalities. ItemReader interface is used to read chunks of data from a data source. Then writes the chunks in a transaction using the ItemWriter interface. Optionally, we can include an ItemProcessor implementation to perform transformations on the data. In majority of the real time use cases, we use Chunk-based Step.

How the Step Execution happens in Spring Batch Processing?

The important part in a whole job execution is the Step Execution. For example, Let’s consider that we want to implement a use case where we want to retrieve records from a CSV file and after few transformation in data(processing) update the records to the database. Let’s assume that we have 10300 records in the CSV file and the chunk size as 400.

Step Execution In Spring Batch



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
javatechonline blog

javatechonline blog

Java, Spring Boot, Microservices Tutorials