My batch job doesn't process all read records.
After finish the job, Spring Batch logs that read 198282 records, but in processor I have a log before start the processing and logged only 196503 , but sometimes, the processor process all.
I'm running the job in multi thread with throttle limit = 20, but sometimes I have this problems, not process all.
ItemReader: JpaPagingItemReader with saveState = false
ItemProcessor:
class MyProcessor implements ItemProcessor<Item, Item> {
@Override
public Item process(final Item item) {
log.info("action=process..");
....
}
}
What could be happening? Spring batch is not sending all records to process or I'm doing something wrong to work with multi thread?
Job
@Bean
public Job myJob (Step myStep) {
return jobBuilderFactory.get("myJob")
.start(myStep)
.build();
}
Step
@Bean
public Step consolidateTaxaRebateJobStep (
JpaPagingItemReader<Item> reader,
ItemProcessor<Item, Item> processor,
ItemWriter<Item> writer,
TaskExecutor taskExecutor) {
return stepBuilderFactory.get("myStep")
.<Item, Item>chunk(200)
.reader(reader)
.processor(processor)
.writer(writer)
.taskExecutor(taskExecutor)
.throttleLimit(20)
.build();
}
Spring Boot Version: 2.0.1
JpaPagingItemReader
s ancestorAbstractItemCountingItemStreamItemReader.read()
is not thread safe, socurrentItemCount++
might cause problems. But ifsaveState
really is false, then it appears the read count should be 0 at the end of the job. Try stepping through the code to see where the read count is getting updated and verify it's thread safe. Or perhaps wrap the JpaPagingItemReader and synchronize the read method before delegating. – Andrew S