In Spring Batch, JobExecution is the runtime record of a single attempt to run a job. It stores the status, start and end times, exit code, job parameters, the step executions and any failures, and it is persisted in the job repository so you can monitor, debug and restart jobs.
A JobInstance is a logical run (a job name plus identifying parameters), and every launch or restart of that instance creates a new JobExecution.
org.springframework.batch.core.JobExecution is created by the framework when a job is launched. The most useful properties are:
| Property | Meaning |
|---|---|
getId() | database id of this execution |
getJobInstance() | the logical instance this belongs to |
getJobParameters() | the parameters of the run |
getStatus() | BatchStatus such as STARTING, STARTED, COMPLETED, FAILED, STOPPED |
getExitStatus() | ExitStatus with an exit code and description, used for flow decisions |
getStartTime() and getEndTime() | when the run started and finished |
getStepExecutions() | one StepExecution per step that ran |
getExecutionContext() | key-value state saved across restarts |
getAllFailureExceptions() | exceptions collected during the run |
In Spring Batch 5 (Spring Boot 3) the time properties are LocalDateTime; earlier versions used java.util.Date. Spring Batch 6 keeps the same concept, so check the migration guide for your exact version.
The relationship explains restart behaviour:
importOrders with the parameter date=2026-11-17. Spring Batch creates a JobInstance and a first JobExecution.FAILED.JobInstance, creates a second JobExecution, and restarts from the failed step.JobInstanceAlreadyCompleteException.To run the same job repeatedly, change an identifying parameter (a timestamp or a run id) or add a JobParametersIncrementer.
With the default synchronous launcher, run returns after the job finishes. With an asynchronous TaskExecutor it returns immediately with a JobExecution in STARTING or STARTED, and you poll later.
In Spring Boot, jobs run at startup by default; set spring.batch.job.enabled=false when you launch jobs yourself.
A JobExecutionListener receives the execution before and after the job, which is the usual place for notifications and cleanup:
Register it on the job builder with .listener(notifyListener).
BatchStatus is an enum the framework uses for control flow and restart decisions. ExitStatus is a string-based code you can customise, for example COMPLETED WITH SKIPS, and use in conditional flows (.on("COMPLETED WITH SKIPS").to(reportStep)). Process exit codes from a command-line launcher are derived from the ExitStatus.
JobExecution.getExecutionContext() is a map saved to the repository at step boundaries. Values you place there survive a restart, so a later execution can read them. Use it for small values such as a last processed file name. Data shared across steps in the same run belongs here too. For per-step state use the StepExecution context.
Because executions are stored in tables (BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_PARAMS, BATCH_STEP_EXECUTION), you can query them with JobExplorer (read-only) or with SQL, and operate them with JobOperator:
Dashboards such as Spring Cloud Data Flow read the same tables.
A JobInstance is the logical job run identified by name and identifying parameters. A JobExecution is one physical attempt to run it; a failed instance can have several executions.
An instance with the same identifying parameters already completed. Add a changing parameter or an incrementer.
Call JobOperator.stop(executionId). The status becomes STOPPING, then STOPPED once the current chunk finishes.
Treat it as owned by the framework while running. Read it from listeners and after completion, and do not modify it from application threads.
JobExecution records one run of a Spring Batch job: its status, exit status, parameters, timing, step executions and failures, persisted so jobs can be monitored and restarted. Combine it with JobInstance for restart semantics, use listeners and JobExplorer for monitoring, and change an identifying parameter whenever you want a new instance.