繁体   English   中英

如何在Spring Batch中使用块处理?

[英]How to use chunk processing with Spring Batch?

我第一次使用Spring Batch。 我尝试了一些示例并通读了文档。 但是我仍然有疑问:

  • 我可以跳过面向块的处理中的一个阶段吗? 例如:我从数据库中获取数据,对其进行处理并确定是否需要更多数据,是否可以跳过写入阶段并执行下一步的读取阶段? 我应该改用Tasklet吗?

  • 如何实现条件流?

非常感谢Florian

只需通过抛出一个已声明为“可跳过的异常”的异常来跳过数据块 您可以按照以下步骤进行操作:

<step id="step1">
   <tasklet>
      <chunk reader="reader" writer="writer"
             commit-interval="10" skip-limit="10">
         <skippable-exception-classes>
            <include class="com.myapp.batch.MyException"/>
         </skippable-exception-classes>
      </chunk>
   </tasklet>
</step>

通过执行步骤执行的ExitStatus可以轻松实现条件流

<job id="job">
    <step id="step1" parent="s1">
        <next on="*" to="stepB" />
        <next on="FAILED" to="stepC" />
    </step>
    <step id="stepB" parent="s2" next="stepC" />
    <step id="stepC" parent="s3" />
</job>

阅读文档以获取有关这些主题的更深入的知识: http : //docs.spring.io/spring-batch/reference/html/configureStep.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM