春季批处理:如果在特定时间未完成,请重试作业 [英] Spring batch: Retry job if does not complete in particular time

查看:101
本文介绍了春季批处理:如果在特定时间未完成,请重试作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用将RetryTemplateSimpleRetryPolicy结合使用的Spring批处理应用程序.

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

在此应用程序中,ItemProcessor通常需要30-35分钟才能完成特定任务.但是有时,完成同一任务需要不到2个小时的时间.

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.

如果分配的任务没有在给定的时间内完成,是否可以重试我的ItemProcessor?

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

我正在寻找一些Java/Spring内置功能,而不是编写自己的超时逻辑.

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

推荐答案

您可以为给定步骤定义transactional-attributes. ( https://docs.spring.io/spring-batch/trunk/reference/htmlsingle/#transactionAttributes )

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>

如果您使用的是Java配置,请检查 https://stackoverflow.com/a/23921558/1942642 .

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

这篇关于春季批处理:如果在特定时间未完成,请重试作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆