Explicit protection against exceptions in SkipPolicy to prevent infinite loop in RetryTemplate

Details

Description

We use a RetryTemplate build using FaultTolerantFactoryBean. When an exception is thrown in one of our custom ErrorListener, the RetryTemplate decides that the exception is not fatal and retries. If that exception is consistently thrown by the ErrorListener the RetryTemplate will retry indefinitely and so an infinite loop will occur.

Yes, sorry, I get confused with all the helpers we made.
The exception is thrown in the shouldSkip() method of a custom implementation of SkipPolicy which was simply given to the FaultTolerantStepFactoryBean. In our case, the SkipPolicy must update a status in database to indicate that the item(s) are in error or skipped. So it can sometimes throw exceptions (in case of problem with database communication,...).

Nicolas Vanhoren
added a comment - 09/Mar/10 3:19 AM Yes, sorry, I get confused with all the helpers we made.
The exception is thrown in the shouldSkip() method of a custom implementation of SkipPolicy which was simply given to the FaultTolerantStepFactoryBean. In our case, the SkipPolicy must update a status in database to indicate that the item(s) are in error or skipped. So it can sometimes throw exceptions (in case of problem with database communication,...).

There is explicit protection in the framework for exceptions thrown by listeners (including skip listeners). Since you throw the exception in the SkipPolicy this won't apply. A workaround is to catch and wrap the exception in something fatal (e.g. RetryException).

Dave Syer
added a comment - 09/Mar/10 6:09 PM There is explicit protection in the framework for exceptions thrown by listeners (including skip listeners). Since you throw the exception in the SkipPolicy this won't apply. A workaround is to catch and wrap the exception in something fatal (e.g. RetryException).