簡體   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