I have following step in batch job.
<batch:step id="parse-step">
<batch:tasklet>
<batch:chunk reader="xmlCommonReader"
processor="xmlCommonProcessor"
writer="xmlCommonWriter"
commit-interval="1">
<batch:skip-policy>
<bean class="org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy" scope="step"/>
</batch:skip-policy>
<batch:retry-policy>
<bean class="org.springframework.retry.policy.NeverRetryPolicy" scope="step"/>
</batch:retry-policy>
</batch:chunk>
</batch:tasklet>
<batch:next on="FAILED" to="file-failed-step"/>
<batch:next on="COMPLETED" to="file-success-step"/>
<batch:listeners>
<batch:listener ref="parseStepExecutionListener"/>
<batch:listener ref="parseStepSkipListener"/>
</batch:listeners>
</batch:step>
When some exception throws, i catch him in parseStepSkipListener and log in database.
I expect the following behavior:
But actually i get following behavior:
So, one chunk of data try to process and write two times.
As with the skip functionality, there are two ways of specifying retry behaviour in Spring Batch. The convenient standard way would be specifying a retry-limit on the chunk and nesting retryable-exception-classes inside the chunk: As with skipping, you may specify your own RetryPolicy and plug it into the chunk:
Spring Batch is a great framework offering functionality for complex processings like skipping or retrying failed items, but you still need to understand what Spring Batch does to avoid problems. In this article we saw potential stumbling blocks when using skip and retry functionality.
Overview By default, a Spring batch job fails for any errors raised during its execution. However, at times, we may want to improve our application's resiliency to deal with intermittent failures. In this quick tutorial, we'll explore how to configure retry logic in the Spring Batch framework.
There’s no rollback. As with the skip functionality, there are two ways of specifying retry behaviour in Spring Batch. The convenient standard way would be specifying a retry-limit on the chunk and nesting retryable-exception-classes inside the chunk: As with skipping, you may specify your own RetryPolicy and plug it into the chunk:
In few words:
This happens because when an error occured in write step SB doesn't know which object caused the exception so a rollback is performed and every single item of last uncommited chunk is processed/writed again as a mini-chunk to detect which object was the cause of main write error. You can read more (with diagrams) here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With