Spring batch: Retry job if does not complete in particular time

孤人 提交于 2019-12-05 01:09:56

问题


I am working on a Spring batch application where I have used RetryTemplate with SimpleRetryPolicy.

In this application, ItemProcessor usually takes 30-35 mins to complete a particular task. But sometimes, it takes from than 2hrs to complete that same task.

Is there a way to retry my ItemProcessor, if the assigned task is not completed within given time period?

I am looking for some Java/Spring in-build functionality instead of writing my own timeout logic.


回答1:


You can define transactional-attributes to a given step. (https://docs.spring.io/spring-batch/trunk/reference/htmlsingle/#transactionAttributes)

Transaction attributes can be used to control the isolation, propagation, and timeout settings.

<step id="step1">
  <tasklet>
      <chunk reader="itemReader" writer="itemWriter" commit-interval="2"/>
      <transaction-attributes isolation="DEFAULT"
                              propagation="REQUIRED"
                              timeout="30"/>
  </tasklet>
</step>

If you're using Java configuration check https://stackoverflow.com/a/23921558/1942642.



来源:https://stackoverflow.com/questions/50098872/spring-batch-retry-job-if-does-not-complete-in-particular-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!