I see 2 ways to do it.
You can implement the ItemProcessListener. This interface is called after/before an item is processed. This interface also reported any errors.
public class ItemCountsListener implements ItemProcessListener<Object, Object> { private static final AtomicLong count = new AtomicLong(1); public void afterProcess(Object item, Object result) { count.getAndIncrement(); } public void beforeProcess(Object item) {} public void onProcessError(Object item, Exception e) { }
}
Or you can call the method
jobExecution.getStepExecutions()
. This method returns aCollection<StepExecution>
object. In this class, there is a methodgetWriteCount
which returns the current number of items written for this execution. I would do something similar to this code :
public void afterJob(JobExecution jobExecution) { int nbItemsProcessed; for (StepExecution stepExecution : jobExecution.getStepExecutions()) { nbItemsProcessed += stepExecution.getWriteCount(); } }