Spring Batch Process Indicator Pattern

╄→гoц情女王★ 提交于 2019-12-21 22:30:35

问题


In a Spring Batch Job I am writing the item to target file (using FlatFileItemWriter) and updating input record "process indicator" field as "processed"/"failed" (using JdbcBatchItemWriter). Which is the best way to make this happen in a "item transaction" ?

  1. Using a CompositeItemWriter (delegates FlatFileItemWriter for writing to file and JdbcBatchItemWriter to update the "process indicator"
  2. Using ItemWriteListener methods "afterWrite" and "onWriteError" to update the "process indicator"

回答1:


The recommended way is to use the ChunkListener#afterChunk to update a flag like that. This allows it to be separate from any retry, etc logic that gets involved in the other two options you proposed.



来源:https://stackoverflow.com/questions/16503993/spring-batch-process-indicator-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!