简体   繁体   中英

Spring Batch flow control

I have a job in spring batch with a reader, a processor and a writer.

First, I would like to know in what order to these 3 components run: are they sequential(for commit-interval=1) or is a new item read before the previous one has been written in order to avoid delays?

I am interested in this, because I have the following case:

I want to have an "assembly-line": read->process->write->read again->...

This means that nothing is read before the previous item has been written.

Is this thing already assured out-of-the-box? If not, how can I accomplish such a thing?

The interaction between an ItemReader, ItemProcessor, and ItemWriter is as follows in Spring Batch:

  • Until the chunk size is reached
    • ItemReader.read()
  • While there are items that have not been processed
    • ItemProcessor.process()
  • ItemWriter.write() // single call for all items in the chunk.

That being said, with the chunk size set to 1, it is processed read, process, write, repeat.

It's important to note that not only is the above contract guaranteed, but each step is run to completion before the next step executes (splits not withstanding).

You can read more about how the various components interact in the documentation here: http://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html#chunkOrientedProcessing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM