Spring Batch: Running A Batch Job Explained

Spring Batch: Running A Batch Job Explained

To run a batch job, a JobLauncher needs a batch JobConfiguration and JobParameters. This creates a JobInstance.

A JobInstance creates a JobExecution. If the job fails and is restarted it retains the same JobInstance but creates a new JobExecution.

A JobExecution runs one or more steps in the Batch_Step_Execution table.

So each new run of a batch job creates a new batch job instance, and each restart creates a new job execution.

This is very important to understand when debugging. If a job fails, it’s important to find the job execution id and find which step it failed on. This failed step in the JobRepository will contain how many records READ/WRITE occurred before the failure and the exit message.