-1

I want my RetryTemplate to have a delay of 300000 ms - 5 minutes multiplied by 1.1 per try. However, it only delays the next attempt by 30 seconds. Here's a simplified example:

@Service
public class Foo {
    private static final Logger log = Logger.getLogger(Foo.class);

    @Retryable(value = Exception.class,
            backoff = @Backoff(delay = 300000, multiplier = 1.1))
    public void run() throws Exception {
        new Bar().run();
    }

    @Recover
    void recover(Exception e) {
        log.error("e", e);
    }
}

public class Bar {
    private static final Logger log = Logger.getLogger(Bar.class);

    public void run() throws Exception{
        log.info("hier");
        throw new Exception();
    }
}

@Bean
CommandLineRunner runner() {
    return (String[] a) -> {
            scheduler.schedule(() -> {
                try {
                    retryTemplate.execute(arg -> {
                        foo.run();
                        return null;
                    });
                } catch (Exception e) {

                }
            }, 1 , TimeUnit.SECONDS);
    };
}

The logs are made on these times:

2017-03-17 13:25:08.439  INFO 6500 --- [ 
2017-03-17 13:25:38.439  INFO 6500 --- [ 
2017-03-17 13:26:08.440  INFO 6500 --- [ 
2017-03-17 13:26:08.444 ERROR 6500 --- [ 

It doesn't make a difference if I use it with or without the scheduler (which is there because the original code needs the initial delay.)

Now if I add a maxDelay to the @Backoff

@Backoff(delay = 300000, multiplier = 1.1, maxDelay = 1000000000)

It works exactly as intended - firing after 5 minutes, then after 5*1.1 minutes and so on. However reading the javadoc for @Backoff - maxDelay, it says it defaults to 0 and is ignored if less than delay

/**
     * The maximimum wait (in milliseconds) between retries. If less than the
     * {@link #delay()} then ignored.
     * 
     * @return the maximum delay between retries (default 0 = ignored)
     */
    long maxDelay() default 0;

Is there anything I didn't understand? It seems like the maxDelay defaults to 30 seconds, which is quite different from what the javadoc explains.

Used spring-retry version is 1.1.3

1 Answers1

1

It's a bug in the javadocs - see the code here.

policy.setMaxInterval(max > min ? max : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL);

and

public static final long DEFAULT_MAX_INTERVAL = 30000L;
Gary Russell
  • 166,535
  • 14
  • 146
  • 179