0PricingLogin
Spring Boot 4 Complete Guide · Lesson

Chunk-Oriented Reader-Processor-Writer Flows

Wire ItemReader, ItemProcessor, and ItemWriter components for scalable chunk processing.

Why Chunk-Oriented Processing?

Spring Batch reads, processes, and writes data in chunks instead of one record at a time. A chunk is a configurable number of items (the commit-interval) handled inside a single transaction.

  • Read N items one by one with an ItemReader.
  • Process each item with an ItemProcessor.
  • Write the whole batch of N at once with an ItemWriter.

Writing in bulk and committing per chunk is what makes batch jobs scale to millions of rows without exhausting memory.

The Three Core Interfaces

Every chunk step is built from three single-method interfaces. Knowing their contracts is the foundation of the whole pattern.

  • ItemReader<I>I read() returns the next item, or null when the input is exhausted.
  • ItemProcessor<I, O>O process(I item) transforms an input into an output; returning null filters the item out.
  • ItemWriter<O>void write(Chunk<? extends O> chunk) persists the accumulated chunk.
public interface ItemReader<I> {
    I read() throws Exception; // null = end of input
}

public interface ItemProcessor<I, O> {
    O process(I item) throws Exception; // null = filter
}

public interface ItemWriter<O> {
    void write(Chunk<? extends O> chunk) throws Exception;
}

All lessons in this course

  1. Jobs, Steps, and the JobRepository Model
  2. Chunk-Oriented Reader-Processor-Writer Flows
  3. Fault Tolerance, Skip, and Retry Policies
  4. Partitioning and Parallel Step Execution
← Back to Spring Boot 4 Complete Guide