Hi All,

Greeting of the day!

Today we will be going through the basics of the spring batch, along with its components and working architecture, so let's start.

What is the spring batch?

Spring batch is a framework provided by spring for bulk processing of data, files, payments, etc asynchronous at the scheduled time.

Main components of spring batch

  • Job Launcher
  • Job
  • Step
  • Tasklet
  • Item Reader, Item Writer, Item Processor
  • Job Repository
Now let's go into details of these components

Job Launcher Ã¨  Is interface provided by spring to launch the job, below is a method of JobLauncher to start job execution. 
    
   JobExecution run(Job job, JobParameters jobParameters)

Job Ã¨Job is the interface that is used to configure job execution steps.

Step Ã¨  Step is an interface used to represent the configuration of step by development.
    
Important Note on Step
  • Step can consist of a tasklet ,or ItemReader,ItemProcessor,ItemWriter
Tasklet Ã¨  Tasklet is used when we need to execute some independent task such as generating reports from database tables, sending emails, etc.

Item Reader Ã¨  ItemReader is an interface that is used to read data example read data from some CSV, XML files.

Item Processor Ã¨ ItemProcessor is an interface used for item transformation, its place where we can apply business logic, validation, and transform data before writing in a database.

Item Writer Ã¨ ItemWriter is an interface used for the writing operation, for example to writer data to a database or some output file after reading or processing.

JobRepository Ã¨ JobRepository is a repository used by spring to persist batch metadata.

Below is a sample flow diagram for the spring batch

  
Hope you now have a basic idea of the spring batch. 

We will be implementing the below example of the Student Report Card in the next session.
  • School authorities will place 1 CSV file in some specific folder. CSV file will contain marks details of each student. 
  • We will be reading CSV files, adding all marks in the Student_Marks table.
  • We will calculate grades of students and add status as pass or fail for all student
  • Also, we will then generate 1 PDF report card per student and will mail it to the student.

It will be having 2 step process as described in the flow chart.




For a detailed example refer to my below post.


Other spring batch articles 





For all java & java 8 tutorials refer to the below page 

For other spring tutorials refer to Spring Tutorial

Thanks
Happy Learning.!!