You manage and monitor Spring Batch jobs through four pieces: JobLauncher (or JobOperator) to start and control executions, the job repository tables that store state, JobExplorer to query that state, and listeners plus Micrometer metrics to observe runs. The examples target Spring Boot 3.x with Spring Batch 5.
Spring Batch records every launch in metadata tables, so a job's history, parameters, status and failures can be inspected at any time, even after the application restarted.
A JobExecution moves through a set of BatchStatus values:
| Status | Meaning |
|---|---|
STARTING | The execution was created and is about to run |
STARTED | The job is running |
STOPPING | A stop was requested and the job is finishing its current work |
STOPPED | The job stopped and can be restarted |
COMPLETED | The job finished successfully |
FAILED | The job ended with an error and can be restarted |
ABANDONED | The execution was marked as not restartable |
UNKNOWN | The state could not be determined, for example after a crash |
Alongside the status there is an ExitStatus, a code and description that you can customise and that Spring Boot uses to compute the process exit code in command-line runs.
Spring Boot runs all Job beans at startup by default. For scheduled or on-demand jobs, disable that and launch yourself.
The default launcher runs synchronously. To return immediately from a web request, configure a TaskExecutorJobLauncher with an executor, and return the execution id so the caller can poll for status.
JobExplorer is the read-only view of the repository. It never changes state, so it is safe to use in monitoring endpoints.
Other useful calls are getJobNames(), findRunningJobExecutions(jobName) and getJobInstances(jobName, start, count). Use findRunningJobExecutions to refuse a new launch when a run is still active.
Listeners give you hooks without touching business code. JobExecutionListener reports job-level events and StepExecutionListener reports step-level counts.
Attach it on the job builder: new JobBuilder("reportJob", jobRepository).listener(new LoggingJobListener()). At step level, StepExecution exposes getReadCount(), getWriteCount(), getSkipCount() and getCommitCount(), which are the numbers operators care about.
JobOperator controls running executions by id:
stop(executionId) asks the job to stop at the next safe point, normally after the current chunk. The execution ends as STOPPED.restart(executionId) restarts a failed or stopped execution.abandon(executionId) marks a stopped execution as ABANDONED so it can never be restarted.If an application crashes while a job is running, its execution stays in STARTED and Spring Batch will refuse to start the same instance again. Mark that execution as FAILED (or abandon it) after you confirm no process is still running it.
With spring-boot-starter-actuator and Micrometer on the classpath, Spring Batch publishes timers such as spring.batch.job and spring.batch.step, plus item counters, tagged with job name and status. Expose them through your registry (Prometheus, for example) and alert on failed statuses, long durations and executions that stay in STARTED. Metrics and the repository tables are enough for most teams; build a small status endpoint if you need a UI.
In the BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_PARAMS and BATCH_STEP_EXECUTION tables of the configured database.
Set spring.batch.job.enabled=false and call JobLauncher.run from a controller, scheduler or command.
No. It was retired long ago. Use JobExplorer, Actuator metrics or your own status endpoint.
Spring Batch 6, used with Spring Boot 4, merges some of these interfaces (for example job exploration and launching move toward JobRepository and JobOperator). The concepts remain; confirm exact class names in the release notes.
Launch with JobLauncher, control with JobOperator, read state with JobExplorer, and observe with listeners and Micrometer metrics. Keep launches unique through parameters, watch for executions stuck in STARTED after crashes, and expose execution status through an endpoint or a metrics dashboard.