问题
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" ?
- Using a CompositeItemWriter (delegates FlatFileItemWriter for writing to file and JdbcBatchItemWriter to update the "process indicator"
- 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