spring-projects / spring-projects/spring-batch
FlatFileItemRead isnt respecting the maxitemcounter [BATCH-2801]
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
Jesús Ponte opened BATCH-2801 and commented
I'm doing a process with Spring Batch multi-thread. My process receives a large txt file (> 100k lines). I want each thread to process X lines of the file and do X process with the information to gain time.
I am using the FlatFileItemRead class passing the initial and final line to each thread. I'm doing tests with 19k lines, 3 and 4 threads and I cannot see why the first thread if it starts and stops in the correct line, but the rest of threads start in the correct line but not end in the correct one, read the file until the end.
The xml configuration and the rangepartitioner files are attached.
My example with 19k lines in file and 3 threads:
Thread: 1
Initial Index: 1
Final Index: 6333
Thread: 2
Index Initial: 6334
Final Index: 12666
Thread: 3
Index Initial: 12667
Final Index: 19000
Thread 1 reads up to 6333. Thread 2 reads up to 19000 instead of reading up to 12666 and thread 3 reads up to 19000.
You can see an example created by Mahmoud Ben Hassine on his GitHub see this
His example (15 lines in file and 3 threads):
- SimpleAsyncTaskExecutor-1 reads from 1 to 5 as expected
- SimpleAsyncTaskExecutor-2 reads from 6 to 15 which is incorrect (it should read from 5 to 10 only)
- SimpleAsyncTaskExecutor-3 reads from 11 to 15 as expected
Affects: 2.1.9, 4.1.1
Reference URL: https://stackoverflow.com/questions/55227133/why-do-these-threads-read-the-entire-file-instead-of-maxitemcounter
Attachments:
- RangePartitioner.java (1.71 kB)
- XML_Configuration.xml (5.10 kB)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the attached RangePartitioner.java and XML_Configuration.xml, then reproduce the 19,000-line, three-thread case described in the issue. Compare each thread's initial and final indexes with its actual reads; done means every thread stops at its assigned final line instead of reading to the file end.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, data-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100