Exit before all attempts in Spring Retryable

Viewed 190

I have written a Retryable in Spring boot. It will retry 5 times, and with a backoff of 5 seconds. I would also like to exit before 5 iterations, if some condition is met. It's like

    @Retryable(value = {SomeException.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000))
    public void checkForProcessed() throws SomeException {
             if(someCondition) {
    //come out of the retryable before retrying for 5 times.

                }
    }

So let's say the condition is met in the third iteration, it should not retry for 2 more times, and should exit in the 3rd iteration itself

1 Answers

Throw SomeOtherException (which is not retryable).

Related