diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 4ad2985..30234ea 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.retry.backoff; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.retry.RetryContext; import org.springframework.util.ClassUtils; @@ -28,9 +29,10 @@ import org.springframework.util.ClassUtils; * This implementation is thread-safe and suitable for concurrent access. Modifications to * the configuration do not affect any retry sets that are already in progress. * - * The {@link #setInitialInterval(long)} property controls the initial value passed to - * {@link Math#exp(double)} and the {@link #setMultiplier(double)} property controls by - * how much this value is increased for each subsequent attempt. + * The {@link #setInitialInterval(long)} property controls the initial delay value for the + * first retry and the {@link #setMultiplier(double)} property controls by how much the + * delay is increased for each subsequent attempt. The delay interval is capped at + * {@link #setMaxInterval(long)}. * * @author Rob Harrop * @author Dave Syer @@ -83,6 +85,7 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicyexp(backOffContext.expSeed)'. */ + @Override public void backOff(BackOffContext backOffContext) throws BackOffInterruptedException { ExponentialBackOffContext context = (ExponentialBackOffContext) backOffContext; try { long sleepTime = context.getSleepAndIncrement(); - if (logger.isDebugEnabled()) { - logger.debug("Sleeping for " + sleepTime); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Sleeping for " + sleepTime); } - sleeper.sleep(sleepTime); + this.sleeper.sleep(sleepTime); } catch (InterruptedException e) { throw new BackOffInterruptedException("Thread interrupted while sleeping", e); @@ -195,8 +200,8 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy maxInterval) { - sleep = maxInterval; + if (sleep > this.maxInterval) { + sleep = this.maxInterval; } else { this.interval = getNextInterval(); @@ -209,22 +214,23 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy