You handle job execution in Spring Batch by launching a Job through a JobLauncher (or JobOperator) with a unique set of JobParameters, and you monitor it by reading the metadata that the JobRepository stores: through a JobExecutionListener while the job runs, and through the JobExplorer afterwards. Every run produces a JobExecution with a BatchStatus, an ExitStatus, and one StepExecution per step, each with read, write and skip counters.
This article uses the Spring Batch 5.x API that ships with Spring Boot 3 (JobBuilder, StepBuilder and JobRepository-based configuration). The old JobBuilderFactory and StepBuilderFactory were removed in 5.0, and Spring Batch 6 continues to consolidate the monitoring APIs, so check your version's reference documentation for renamed types.
A job is started by calling JobLauncher.run(job, parameters). By default Spring Boot also launches every Job bean at application startup (controlled by spring.batch.job.enabled, and spring.batch.job.name when you have several jobs). For web-triggered or scheduled runs, disable the startup run and launch the job yourself.
The default launcher is synchronous, so run returns only when the job finishes. For an HTTP endpoint you normally want to return immediately. Configure a TaskExecutorJobLauncher with a TaskExecutor, and run returns a JobExecution whose status is still STARTING or STARTED. You then poll its id.
Two values describe the outcome, and they are not the same thing.
| Type | Purpose | Values |
|---|---|---|
BatchStatus | Framework state of the execution | STARTING, STARTED, STOPPING, STOPPED, COMPLETED, FAILED, ABANDONED, UNKNOWN |
ExitStatus | Outcome code used for flow decisions and process exit codes | Free-form string such as COMPLETED, FAILED, NOOP or your own value |
BatchStatus is an enum that the framework manages. ExitStatus is a string you can customise, for example to return COMPLETED WITH SKIPS from a listener, and flow transitions (.on("...")) match against it.
JobExplorer is a read-only view of the batch metadata tables. Use it to answer "what is the state of execution 42?" from another thread, another request or another node.
Example output for a finished run:
JobExplorer can also list running executions with findRunningJobExecutions(jobName) and recent instances with getJobInstances(jobName, start, count). This is the basis for a "currently running" admin page.
A JobExecutionListener runs before and after the job, and a StepExecutionListener does the same per step. In Spring Batch 5 both interfaces have default methods, so implement only what you need. The old JobExecutionListenerSupport class is deprecated.
Register it on the job with new JobBuilder("importJob", jobRepository).listener(jobLoggingListener). In Spring Batch 5.x, getStartTime() and getEndTime() return LocalDateTime, so Duration.between works directly. Older 4.x code returned Date.
You do not need to hand-write counters. When Micrometer is on the classpath (for example via Spring Boot Actuator), Spring Batch publishes timers and counters such as spring.batch.job, spring.batch.step and spring.batch.job.active. Expose them through /actuator/metrics or a Prometheus registry and alert on failed or long-running jobs. Pair this with the metadata tables for history that outlives a restart.
You can ask a running job to stop gracefully with JobOperator.stop(executionId). The status becomes STOPPING and then STOPPED once the current chunk commits. A FAILED or STOPPED execution is restartable: launch the same job with the same identifying parameters and Spring Batch resumes from the last committed chunk, as long as the readers store their state. A COMPLETED instance cannot be run again with the same identifying parameters and throws JobInstanceAlreadyCompleteException.
JobLauncher only starts a job with given parameters. JobOperator adds lifecycle operations by name or id: start, stop, restart, abandon and inspect summaries.
A job instance is identified by its job name plus its identifying parameters. If a previous instance with the same parameters completed, Spring Batch refuses to run it again. Add a changing parameter or a JobParametersIncrementer such as RunIdIncrementer.
Set spring.batch.job.enabled=false and launch the job from a controller, scheduler or command line runner yourself.
In the BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_PARAMS and BATCH_STEP_EXECUTION tables of the configured DataSource. Boot 3 can create them with spring.batch.jdbc.initialize-schema.
Launch jobs with a JobLauncher using unique identifying parameters, and use an asynchronous launcher when the caller must not block. Track progress with BatchStatus, ExitStatus and step counters read through JobExplorer, hook into the lifecycle with JobExecutionListener, and export Micrometer metrics for dashboards and alerts. Failed or stopped executions can be restarted with the same identifying parameters.