3

If I define like this for spring batch:

<chunk reader="chunkReader" 
    writer="chunkWriter" 
    processor="chunkProcessor" 
    commit-interval="#{jobParameters['commitSize']}" />

In this spring batch's chunk-oriented processing, are the chunks processed in parallel? And are the individual items in the chunks processed in parallel?

I am asking mainly to see if I need to worry about multithreading and race conditions.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
Neeraj Gupta
  • 765
  • 1
  • 10
  • 18
  • 1
    It is simply defining a chunk in chunk-oriented step. Nothing to do with multi-threading or parallel processing. You need to show the enclosing tasklet definition to see if it has defined a taskExecutor for multi-threaded execution: https://docs.spring.io/spring-batch/4.0.x/reference/html/scalability.html#multithreadedStep – Adrian Shum May 29 '18 at 01:30

1 Answers1

2

Unless you instruct Spring, it will be all sequential.

If you decide to use multithreading, a batch job can use Spring’s TaskExecutor abstraction to execute each chunk in its own thread. A step in a job can be configured to perform within a threadpool, processing each chunk independently. As chunks are processed, Spring Batch keeps track of what is done accordingly. If an error occurs in any one of the threads, the job’s processing is rolled back or terminated per the regular Spring Batch functionality.

See: https://docs.spring.io/spring-batch/trunk/reference/html/scalability.html

and

How to set up multi-threading in Spring Batch?

gargkshitiz
  • 2,130
  • 17
  • 19