Spring Batch: Running a Batch Job Explained
To run a batch job, a JobLauncher needs a batch JobConfiguration and JobParameters. This creates a JobInstance.
To run a batch job, a JobLauncher needs a batch JobConfiguration and JobParameters. This creates a JobInstance.
Batch jobs are created in Spring Batch using the JobBuilderFactory. A custom job builder factory can be created and re-used to allow common job configurations to be shared across all batch jobs in a project.
When a batch job fails it’s useful to automatically send a notification or trigger some sort of an action.
An key thing to remember in Spring Batch is that an instance of a Spring Batch job can only be restarted if it FAILED. If the job completeds SUCCESSFULLY a new instance of the job will have to be created to run it again.
In Spring Batch, when configuring a step you can set the chunk size.
When running multiple batch jobs in Spring Batch, the default JobLauncher waits to launch a job until the previous job running is COMPLETE. In order to run multiple batch jobs simultaneously, the JobLauncher must be configured to run jobs asynchronously.
Often in designing batch jobs you want to limit the frequency that a job can run. For example, if you want a batch job to run once a day, you can use @Scheduled annotation to run the batch job once a day. This is enough if you only run one instance of the batch program and there are no other ways to launch the job.
When defining a Spring batch step, often common configurations are added to almost every step. In order to not violate DRY (Don’t Repeat Yourself), a StepBuilder can be customized upstream with all the shared configurations.
In Spring Batch, in order to get the job_execution_id of the last batch job instance for a given batch job name use this query: