Is there a way to get the number of written records before an exception occurs in a chunk in spring batch? For example, if my commit interval is 1000, and the first 900 writes are successful, and 901st record failed leading to chunkError, I wanted to update an audit file as 900. Is there any attribute that I can use from stepExecution for this?
0
votes
In this use case, are you expecting the 900 to have been rolled back because of the transaction rollback or are you configuring it not to rollback?
- Michael Minella
Hi michael..i wanted to stop execution and not rollback for the ones that were already written to queues.
- rajesh kumar
Hi Michael..i implemented it by having an instance variable incremented for each record in writer and have the writer implement stepexecutionlistener and itemwriterlistener.When an exception occurs,i put the instance variable counter in stepexecution and write it yo audit file.Is this good way of designing /implementing it?
- rajesh kumar
1 Answers
0
votes
Afaik, starting from Spring Batch 2, API related to chunk-oriented processing has changed.
ItemWriter is taking the whole chunk of items as a list. Therefore, unless the ItemWriter implementation you are using records down the failing item, there is no way the Step itself can know about it as it is all hidden within the ItemWriter.
You may need to check the ItemWriter implementation you are using to see if it is saving any info in anywhere (e.g. in ChunkContext / StepExecutionContext etc)