简体   繁体   中英

From boot Spring Batch application @BeforeStep method of the ItemWriter calling before of @BeforeStep method of the ItemProcessor

I'm studing SpringBatch, I have a problem during the boot Spring call ItemWriter before ItemProcessor. Why?

public class PollingReader implements ItemReader<File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) throws NotDirectoryException {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
}
    
public class PollingWriter implements ItemWriter<File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
..
}

public class PollingProcessor implements ItemProcessor<File, File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
}

And the method of the @AfterStep ItemProcessor is called before of the method @AfterStep ItemWriter.

I expected this cycle call for @BeforeStep:

  • ItemReader
  • ItemProcessor
  • ItemWriter

but I have this result:

  • ItemReader
  • ItemWriter
  • ItemProcessor

and for @AfterStep I expected:

  • ItemWriter
  • ItemProcessor
  • ItemReader.

but I have this result:

  • ItemProcessor
  • ItemWriter
  • ItemReader

Thanks:)

Your objects are polymorphic: they are both item reader/processor/writer and StepExecutionListener s (as proxies, to be more precise). When Spring Batch runs StepExecutionListeners before/after a step, it does not see them as reader/processor/writer, and the order of their execution is not necessarily the same as they are called in a chunk-oriented step (in fact, the order is undefined in that case).

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