我在批处理作业中有以下步骤 .
<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>
当一些异常抛出时,我在 parseStepSkipListener 中捕获他并登录数据库 .
我期待以下行为:
-
工作开始
-
执行上一步骤
-
开始执行 parse-step
-
阅读项目
-
处理项目
-
写
-
Ooooops,例外 .
-
捕获异常,登录数据库,转到下一个块(读取,处理,写入) .
-
继续执行其他步骤 .
-
完成工作 .
但实际上我得到以下行为:
-
工作开始
-
执行上一步骤
-
开始执行 parse-step
-
阅读项目
-
处理项目
-
写
-
Ooooops,例外 .
-
处理项目
-
写项目
-
Ooooops,例外 .
-
捕获异常,登录数据库,转到下一个块(读取,处理,写入) .
-
继续执行其他步骤 .
-
完成工作 .
因此,一大块数据尝试处理和写入 two 次 .
1 回答
简而言之:
发生这种情况是因为当写入步骤SB中发生错误时,不知道哪个对象导致异常,因此执行回滚并且最后一个未提交的块的每个项目再次作为迷你块处理/写入以检测哪个对象是原因主写错误 . 你可以阅读更多(附图)here