Spring Batch Job Parameters and Restarting Failed Jobs
Fast recall
Quick revision
Core answer
JobInstance — the same Job name plus the same parameters always map to the same instance, preventing duplicate runs. When a job fails, its JobExecution is marked FAILED in the JobRepository, and re-launching with the same parameters triggers a restart that skips already-committed steps and resumes from the last failed or incomplete step. The reader's position (saved in ExecutionContext as read_count) is the checkpoint — FlatFileItemReader seeks forward by line count, paging readers skip by offset, and partitioned jobs restart only the failed partitions.Understanding of `JobInstance` vs `JobExecution` and the idempotency model Spring Batch enforces by design
Adding a timestamp or run-id parameter every time to force a new `JobInstance` — valid, but candidates should know it also defeats automatic restart for that run
Mention `@StepScope` and `@JobScope` for late binding of parameters into readers/writers, and how `JobParametersIncrementer` enables scheduled reruns without breaking restart
Interview-ready guide
Interview answer
Spring Batch's restart capability is one of its most powerful features — a job that fails at record 50,000 can resume from record 50,001 rather than starting over. This requires understanding how parameters, instances, and executions relate.
The identity model:
JobInstance= Job name +JobParameters; represents a logical runJobExecution= one physical attempt of aJobInstance; a failed JobInstance gets a new JobExecution on restartStepExecution= one attempt of one step; storesread_count,write_count,commit_count, plus theExecutionContextfor restart state
Starting vs restarting:
- First run:
jobLauncher.run(job, params)creates a new JobInstance and JobExecution - Restart: same parameters find the existing FAILED JobInstance and create a new JobExecution; completed steps are skipped
- A COMPLETED JobInstance cannot be re-launched by default — use
allowStartIfComplete(true)per step if needed
Late binding with `@StepScope`:
@StepScope @Bean FlatFileItemReader reader(@Value("#{jobParameters['inputFile']}") String file)- The file value is not available at context load time;
@StepScopedefers bean creation until the step starts - Essential for parameterized readers and writers
Parameter design:
- Business parameters are identity (
processingDate,region) - Technical parameters are additive (
run.idfromRunIdIncrementer) - Conflating them — like UUID on every launch — defeats restart entirely
In an interview, I'd emphasize the JobInstance vs JobExecution distinction and the late binding via @StepScope — both are common gotchas that signal production experience.
Spring Batch Job Parameters and Restarting Failed Jobs
Direct Answer
Job parameters uniquely identify a JobInstance — the same Job name plus the same parameters always map to the same instance, preventing duplicate runs. When a job fails, its JobExecution is marked FAILED in the JobRepository, and re-launching with the same parameters triggers a restart that skips already-committed steps and resumes from the last failed or incomplete step. The reader's position (saved in ExecutionContext as read_count) is the checkpoint — FlatFileItemReader seeks forward by line count, paging readers skip by offset, and partitioned jobs restart only the failed partitions.
Common Mistakes & Pitfalls
Adding a timestamp or run-id parameter every time to force a new JobInstance — valid, but candidates should know it also defeats automatic restart for that run
Check your understanding
Answer these without looking back at the article.
- What happens if you try to restart a COMPLETED job without changing its parameters?
- How would you design a daily batch job so each day's run is independent but also restartable on failure?
- How does Spring Batch store job execution metadata and which BATCH_* tables are involved?
- When would you use `allowStartIfComplete(true)` on a step?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.