【问题标题】:How to use chunk processing with Spring Batch?如何在 Spring Batch 中使用块处理?
【发布时间】:2014-03-31 14:55:08
【问题描述】:

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

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

  • 如何实现条件流?

非常感谢, 弗洛里安

【问题讨论】:

  • 我很困惑。为什么我投了反对票?

标签: spring batch-processing spring-batch


【解决方案1】:

跳过块只需抛出一个已声明为“可跳过的异常”的异常。你可以这样做:

<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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多