0

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

4
  • Your question is not clear. What do you mean by "should be passed to writer at once"? Can you explain what are trying to achieve without referring to Spring Batch? Commented May 8, 2019 at 12:29
  • I have edited question to give more clarity Commented May 8, 2019 at 14:07
  • At which moment you will know commit-interval then? Only when performing SELECT query? Commented May 8, 2019 at 14:19
  • @Atul Could you please provide your solution how did you achieved to set commit-interval dynamically ? Commented Jul 31, 2021 at 16:54

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.