1
votes

i have a batch step

  <batch:step id="read-process-input-file">
  <batch:tasklet>
    <batch:chunk commit-interval=1000
                 reader="item-reader"
                 processor="item-processor"
                 writer="item-writer"
                 skip-limit=1000>

      <batch:skippable-exception-classes>
        <batch:include class="java.lang.Exception"/>
      </batch:skippable-exception-classes>

    </batch:chunk>
  </batch:tasklet>
  <batch:listeners>
    <batch:listener ref="entityOperationExceptionHandler"/>
    <batch:listener ref="filenameListener"/>
    <batch:listener ref="promotionListener"/>
  </batch:listeners>
</batch:step>
  • How does reader and processor flow works?Does reader reads a chunk and waits for processor to process it or it reads all the chunks in a go.
1

1 Answers

4
votes

The reader is called to read one item, which is then passed to the processor. The result of the processor is cached. This is repeated until the commit interval has been reached. The cached processor results will then be passed to the writer, and the transaction committed.

If there is more work to do, the whole sequence starts again.

All this is happening in one thread, so the reading - processing - reading - processing ... is done sequentially.

UPDATE: I just learned that this is not strictly true. The sequence I described is certainly valid for the JSR 352 implementation of Spring Batch (which is what I was using), and since the documentation stated the same for the "classic" implemetation I assumed it must be true.

However, the answer to this question shows that there is a difference: Spring Batch documentation about chunk-oriented step versus reality?

So, for the non-JSR 352 implementation the sequence is reading - reading - reading ... processing - processing - processing ... writing