Hi all,
I'm using MultiResourceItemWriter to split the output of a chunk oriented tasklet with commit-interval = itemCountLimitPerResource.
This was producing the expecting result (several output files with a maximum of itemCountLimitPerResource lines per file), until I set the item read number as a multiple of itemCountLimitPerResource with the following scenario:
- commit-interval = itemCountLimitPerResource = 5,
- read a 10 lines file,
- process
- write using MultiResourceItemWriter and a FlatFileItemWriter as a delegate.
This produces 3 output files (and not 2 as I expected): 2 with 5 lines each, and an empty 3rd one. I dug into MultiResourceItemWriter source code, and themethod, which create the file on the filesystem viaCode:setResourceToDelegate()is called on MultiResourceItemWriter.open() and in MultiResourceItemWriter.write() when ifCode:file.createNewFile()Hence, just after writing the last item in the 2nd file, the value of currentResourceItemCount is 5, and the test passes: a 3rd file is created on the filesystem, but nothing will be written into it, because the last input item has been read, processed and written.Code:(currentResourceItemCount >= itemCountLimitPerResource)
I wonder if this is a bug, or if there is a good reason for this I didn't see.
Also, I wanted to subclass MultiResourceItemWriter and only override the needed methods, but nearly everything is private (protected access of fields and methods should be the way to go for a framework like Spring Batch). I thinkshould only be called if the file is not already opened on MultiResourceItemWriter.write(), and then passed to the delegate writer.Code:file.createNewFile()
Did anyone encountered this kind of behavior?
Spring Batch version: 2.1.1 Release.
Christian.


Reply With Quote