Spring Batch Parallelism: Multi-Threaded, Async, Partitioning
Fast recall
Quick revision
Core answer
split in the job flow. Async processor/writer wraps each item in a Future on a thread pool — best when the processor is I/O-bound. Partitioning splits input into ranges; a master step launches N worker steps locally or on remote JVMs via messaging — scales best and preserves restartability per slice. Choose based on where the bottleneck is: CPU (partitioning / multi-threaded), per-item I/O (async), independent workloads (parallel steps).Understanding of Batch concurrency primitives, when each applies, thread-safety/restartability trade-offs
Using multi-threaded step with non-thread-safe reader; partitioning when a simpler strategy would work
Discuss `Partitioner` interface, grid size vs thread pool size, remote partitioning with Kafka/AMQP, restart semantics per strategy
Interview-ready guide
Interview answer
Spring Batch has four parallelism strategies, and the right one depends on where the bottleneck is.
Multi-threaded step:
- One step, multiple threads share reader/writer
- Reader must be thread-safe — wrap in
SynchronizedItemStreamReader - Restart semantics weaken —
ExecutionContextposition imprecise - Use for I/O-bound steps where restart-order isn't critical
Parallel steps via split:
- Independent steps run concurrently using a
TaskExecutor - Each step has its own reader/writer — no thread-safety issues
- Each has independent restart state
- Use for genuinely independent workloads (loading reference tables in parallel)
Async processor/writer:
AsyncItemProcessorwraps the processor in aFutureon a thread poolAsyncItemWriterunwraps the futures and writes actual results- Reader stays single-threaded — no thread-safety issues
- Use when the processor is I/O-bound (HTTP calls, external lookups)
Partitioning:
- Master step splits input via
Partitionerinto N slices - Each slice runs as an independent worker step with its own reader/writer
- Local partitioning — workers in one JVM via
TaskExecutor - Remote partitioning — workers on separate JVMs via Kafka, AMQP, JMS messaging
- Worker step must be
@StepScopeto receive partition context via@Value("#{stepExecutionContext['x']}") - Best scalability + restart semantics — failed partitions restart independently
Decision framework:
- Bottleneck in processor (per-item I/O) → async processor/writer
- Multiple independent workloads → parallel steps
- Huge dataset that splits naturally → partitioning
- Simple single-machine, restart not critical → multi-threaded
- None fit or small dataset → stay single-threaded; tune chunk size and writer choice first
Pitfalls to call out:
- Multi-threaded + non-thread-safe reader — corruption
- Partitioning + non-idempotent writer — duplicates on restart
- Oversized/undersized grid — framework overhead or idle workers
- Skewed partitioner — one worker does 90% of work; prefer hash for uniformity
- Writer contention on a single DB index — all partitions serialize on the same lock
In an interview I'd emphasize that you measure first, then pick the strategy. Multi-threaded step is rarely the right answer in 2026 — async or partitioning almost always beat it on both performance and correctness.
Spring Batch Parallelism: Multi-Threaded, Async, Partitioning
Direct Answer
Spring Batch has four parallelism strategies. Multi-threaded step runs one step on multiple threads sharing the reader/writer (reader must be thread-safe; restart weakens). Parallel steps run independent steps concurrently via a split in the job flow. Async processor/writer wraps each item in a Future on a thread pool — best when the processor is I/O-bound. Partitioning splits input into ranges; a master step launches N worker steps locally or on remote JVMs via messaging — scales best and preserves restartability per slice. Choose based on where the bottleneck is: CPU (partitioning / multi-threaded), per-item I/O (async), independent workloads (parallel steps).
Common Mistakes & Pitfalls
Using multi-threaded step with non-thread-safe reader; partitioning when a simpler strategy would work
Check your understanding
Answer these without looking back at the article.
- Why does multi-threaded step break restart semantics, and how do you work around it?
- How would you implement remote partitioning with Kafka as the message channel?
- What is data skew in partitioning, and how do you detect and fix it?
- When would AsyncItemProcessor be the wrong choice?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.