5

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.

Pedro Tavares
  • 1,119
  • 8
  • 19
Sachin Mhetre
  • 4,465
  • 10
  • 43
  • 68

1 Answers1

6

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.

Pedro Tavares
  • 1,119
  • 8
  • 19