To configure fault recovery for high-volume datasets in Spring Batch, build a chunk-oriented step with .faultTolerant(), then combine three tools: retry for transient errors (a deadlock, a timeout), skip for bad records (a malformed row), and restartability through the JobRepository for everything else. Keep chunks small enough that a rollback is cheap, and choose the exception classes for each tool deliberately.
The examples below target Spring Batch 5.x on Spring Boot 3.x, where you build steps with StepBuilder and pass the JobRepository and a PlatformTransactionManager explicitly. StepBuilderFactory and JobBuilderFactory were deprecated in 5.0 and removed in 6.0.
In a chunk-oriented step, Spring Batch reads items one at a time, processes them, and writes them in a single transaction per chunk. When something throws, the framework decides what to do based on the fault-tolerance configuration:
| Failure type | Typical cause | Tool | Effect |
|---|---|---|---|
| Transient | Deadlock, connection reset, timeout | Retry | Same item or chunk is attempted again, with back-off |
| Bad data | Parse error, constraint violation on one row | Skip | Item is dropped and counted, the job continues |
| Fatal | Out of memory, schema mismatch, bug | Fail and restart | Step fails, the job restarts later from the last committed chunk |
Without .faultTolerant(), any exception in the reader, processor or writer fails the step. Enabling it adds the retry and skip logic around the chunk.
This configuration retries deadlocks and timeouts up to three times, and skips unparseable rows up to a fixed limit.
retry(...) and skip(...) take exception classes, and subclasses match too. retryLimit is the number of attempts for a single item. skipLimit is the total number of skips the step tolerates before it fails, so size it as a percentage of the expected volume rather than a magic number.
A fixed retry with no pause can hammer a database that is already struggling. Configure a back-off policy on the step, and use a custom SkipPolicy when the decision depends on runtime state, such as an error ratio.
Attach it with .skipPolicy(new RatioSkipPolicy(0.01, 10_000)) in place of .skip(...) and .skipLimit(...). Call itemSeen() from an ItemReadListener or from the processor so the denominator advances. In this example the job tolerates 1 percent bad rows after the first 10,000 items.
Back-off for retries is set on the step builder (.backOffPolicy(...)) with a Spring Retry ExponentialBackOffPolicy, for example an initial interval of 500 ms with a multiplier of 2. Spring Batch 6 moves retry onto the retry support in Spring Framework 7, so check the migration guide for the exact types when you upgrade.
Skipping silently loses data. Register a SkipListener that writes the item and the reason to an error table or file, so an operator can review and replay.
Keep this listener cheap and make the error write run in its own transaction if it must survive a rollback of the chunk.
Two settings decide how painful a failure is on millions of rows.
JobRepository stores a step execution context with the reader position. If the JVM dies, launching the job again with the same identifying parameters resumes from the last committed chunk, provided the reader is restartable (JdbcPagingItemReader, FlatFileItemReader and JpaPagingItemReader save state by default). Give readers a stable name so the state is stored under a predictable key.For throughput, a processor must be idempotent when retried, and the writer should use batch operations such as JdbcBatchItemWriter. For very large volumes, partition the step or use a multi-threaded step, and remember that a saveState reader is not thread-safe in a multi-threaded step.
Retry attempts the same work again, hoping a transient condition clears. Skip gives up on one item and moves on. A common pattern is to retry an exception a few times and skip the item when the retries run out, by listing the same exception in both retry and skip.
Skipped items still count as read and filtered in the step metrics, and the chunk commits with the remaining items. Check StepExecution.getSkipCount() and the read, write and skip counts to see what happened.
The skipLimit on the builder is fixed once the step is built. For runtime decisions, use a custom SkipPolicy that reads from job parameters or step execution context.
That is the scan phase. After a write failure, the framework re-processes the chunk one item at a time to isolate the faulty record, so a large chunk size makes failures expensive.
Use .faultTolerant() with retry for transient exceptions, skip or a custom SkipPolicy for bad records, and a SkipListener so rejected items are stored and not lost. Keep chunks modest, use restartable readers with stable names, and make processors idempotent. On Spring Batch 5 use StepBuilder and JobBuilder with an explicit JobRepository, and review the retry types when you move to Spring Batch 6.