Reputation: 1590
I have a Spring batch job
with standard reader , writer and processor
I have a simple requirement like below :
1)Whatever records reader reads all should be passed to writer by processing through processor
2)My reader reads records by SQL query So if reader reads 100 records , all should be passed to writer at once
3)If it reads 1000 records , all 1000 should be passed at once
4)So in essence , commit-interval is dynamic here and not fixed.
5)Is there any way we can achieve this ?
EDIT :
To give more clarity , in sprint batch , commit-interval plays a role of chunk oriented processing E.g : if chunk-size = 10 , reader reads 10 records , passes one record 1 by 1 to processor and at commit-interval (count = 10 ) , all records are written by writer .
Now what we want is dynamic commit-interval. Whatever is being read by reader , all will be passed to writer at once
Upvotes: 0
Views: 2047
Reputation: 901
Can be achieved using chunk-completion-policy property.
<step id="XXXXX">
<tasklet>
<chunk reader="XXXReader"
processor="XXXProcessor"
writer="XXXWriter"
chunk-completion-policy="defaultResultCompletionPolicy">
</chunk>
</tasklet>
</step>
<bean id="defaultResultCompletionPolicy" class="org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy" scope="step"/>
Also we can write custom chunk-completion policy
see this post
Spring Batch custom completion policy for dynamic chunk size
Upvotes: 0