Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Batch Process Indicator Pattern

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"
like image 429
Ajith Jose Avatar asked Feb 10 '26 21:02

Ajith Jose


1 Answers

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.

like image 152
Michael Minella Avatar answered Feb 12 '26 16:02

Michael Minella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!