Replies: 2 comments
-
There are two issues here: 1. The reader is skipping itemsThis is due to the fact that you are changing the item's status in the processor, which is the criteria used when reading items. In that case, the reader is not able to maintain the sorting result from the JPA context, and might skip items. This is a known issue with paging readers, see https://stackoverflow.com/questions/26509971/spring-batch-jpapagingitemreader-why-some-rows-are-not-read and https://stackoverflow.com/questions/76543864/repositoryitemreader-skipping-items-in-spring-batch-v5. You should use a cursor-based reader instead. 2. A deadlock due to concurrencyThe item writer you shared is not thread-safe, so you can't use it as such in a concurrent step. You need to synchronize access to the Please check and let us know if you need more help on this. |
Beta Was this translation helpful? Give feedback.
-
I believe I answered all the questions. But if that is not the case, please add a comment here. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I believe that the reader when working in a multithread chunk based processing is duplicating the records across multiple threads. I have tried to put some details and analysis below
Using the spring batch version 4.3.7 I have created a simple application which has USER entity. The RepositoryItemReader builds the reader using the JPA repository, and the step configuration is done with Chunk size 10, input and output as the same entity object (User).
In the Processor each item (User) is set with the status='PROCESSED'.
Writer writes the entity finally to the database.
There are total of 99 records.
When the batch starts it fails to complete with the error.
Workaround: To fix this issue I tried with the stepBuilder chunk with 2 different input and output, it works fine with no stuck situation.
I have the complete code in the GitHub for review.
https://github.com/manoop/batch/tree/bugfix/thread-transaction
Spring batch version 4.3.7
Java 8
MySQL
Error while running the batch
##Batch Config
##Processor
Writer
Beta Was this translation helpful? Give feedback.
All reactions