Step Processing & Item Flow
How a step actually moves data: the chunk loop, readers, processors and writers, listeners, and the transaction boundary. This is where most practical Spring Batch questions live.
part ofSpring Frameworkoverview, primer and where to startread it →on this pageshowhide
explore
- Chunk-Oriented Processing4 questions
- ItemReader Implementations5 questions
- ItemProcessor5 questions
- ItemWriter5 questions
- Tasklet Steps5 questions
- Read-Process-Write Transaction Boundary5 questions
- Flat-File Mapping & Tokenizing5 questions
questions
page 2 of 2A cleanup Tasklet that returns CONTINUABLE to delete data in batches fails halfway. What determines whether the restarted job resumes correctly, and how do you design for it?
basics
~20 sBecause each CONTINUABLE pass commits its own transaction, completed batches stay deleted. On restart the whole step re-runs execute() from the start, so correctness depends on the work being idempotent or on progress saved in the ExecutionContext.
How do you keep non-transactional side effects (emails, REST calls, external queues) from being duplicated or corrupted when a chunk transaction rolls back?
basics
~20 sRollback only undoes transactional resources, not emails or REST calls. Make those side effects idempotent, or defer them until after commit, or stage them in the same transactional store and process later. Never assume rollback un-does external effects.
You need to read a large XML file with StaxEventItemReader inside a multi-threaded step, and guarantee correct restart. What issues arise and how do you address them?
basics
~20 sStaxEventItemReader streams XML fragments via StAX and is stateful, so it is not thread-safe and its restart state can't be safely shared across threads. Either keep the step single-threaded, wrap it in SynchronizedItemStreamReader, or partition the input; be aware synchronizing serializes reads and can make saved state inconsistent.
You must write each chunk to an external REST API that has no batch endpoint and is only at-least-once reliable. How do you design the ItemWriter for correctness under Spring Batch retries/restarts?
basics
~20 sImplement a custom ItemWriter that loops the chunk calling the API, but make each call idempotent (send a client-generated idempotency key per item) so retries and restarts don't create duplicates. Track progress so restart resumes cleanly.
showing 31–34 of 34