Is a thread-safe ItemReader needed in a multi-threaded step with the new concurrency model of Spring Batch 6 ? #5214
-
|
Hi, With the new concurrency model of Spring Batch 6, It seems that the reader doesn't need to be thread-safe anymore (I have verified that myself, and the behaviour is the same with or without a thread-safe reader). Chapter https://docs.spring.io/spring-batch/reference/scalability.html#multithreadedStep of the reference documentation still mentions the need for a thread safe reader. Are there other usecases where a thread-safe reader is still needed ? My step definition : var step = new StepBuilder("my_step", jobRepository)
.<I, O>chunk(5)
.transactionManeger(transactionManager)
.reader(reader)
.writer(writer)
.taskExecutor(taskExecutor)
.build(); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Yes, with the new concurrency model, the reader is only called by a single thread and does not have to be thread-safe. I gave some details about that here: #4955 (comment). Does that clarify things better for you? I need to write about that elsewhere for more visibility.
That's an oversight, I will update the documentation accordingly.
Not with the step implementations provided by Spring Batch. We kept the synchronised wrappers around for anyone implementing a custom step and who might need to wrap the reader/writer in a synchronized decorator. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your answer ! Also, for those who are using multi-threaded chunk steps, the writing part is not concurrent anymore. By using local-chunking (introduced in this version too, needs an additional dependency to spring-batch-integration), I managed to have a behaviour similar to that of Spring Batch 5. |
Beta Was this translation helpful? Give feedback.
Yes, with the new concurrency model, the reader is only called by a single thread and does not have to be thread-safe. I gave some details about that here: #4955 (comment). Does that clarify things better for you?
I need to write about that elsewhere for more visibility.
That's an oversight, I will update the documentation accordingly.
Not with the step implementations provided by Spring Batch. We kept the synchronised wrappers around for anyone imp…