This is an automated email from the ASF dual-hosted git repository.

aaronai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new c969c6e  Update the algorithm of ExponentialBackoffRetryPolicy (#104)
c969c6e is described below

commit c969c6e47d15da27832820ae1bb0bc82823f2eae
Author: Aaron Ai <[email protected]>
AuthorDate: Sun Jul 31 14:14:15 2022 +0800

    Update the algorithm of ExponentialBackoffRetryPolicy (#104)
---
 .../client/java/retry/ExponentialBackoffRetryPolicy.java       | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git 
a/java/client/src/main/java/org/apache/rocketmq/client/java/retry/ExponentialBackoffRetryPolicy.java
 
b/java/client/src/main/java/org/apache/rocketmq/client/java/retry/ExponentialBackoffRetryPolicy.java
index 8b25579..ed82dfe 100644
--- 
a/java/client/src/main/java/org/apache/rocketmq/client/java/retry/ExponentialBackoffRetryPolicy.java
+++ 
b/java/client/src/main/java/org/apache/rocketmq/client/java/retry/ExponentialBackoffRetryPolicy.java
@@ -24,11 +24,9 @@ import apache.rocketmq.v2.ExponentialBackoff;
 import com.google.common.base.MoreObjects;
 import com.google.protobuf.util.Durations;
 import java.time.Duration;
-import java.util.concurrent.ThreadLocalRandom;
 
 /**
- * The {@link ExponentialBackoffRetryPolicy} defines a policy to do more 
attempts when failure is encountered, mainly
- * refer to <a 
href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md";>gRPC 
Retry Design</a>.
+ * The {@link ExponentialBackoffRetryPolicy} defines a policy to do more 
attempts when failure is encountered.
  */
 public class ExponentialBackoffRetryPolicy implements RetryPolicy {
     private final int maxAttempts;
@@ -60,12 +58,12 @@ public class ExponentialBackoffRetryPolicy implements 
RetryPolicy {
     @Override
     public Duration getNextAttemptDelay(int attempt) {
         checkArgument(attempt > 0, "attempt must be positive");
-        double randomNumberBound = Math.min(initialBackoff.toNanos() * 
Math.pow(backoffMultiplier,
+        double delayNanos = Math.min(initialBackoff.toNanos() * 
Math.pow(backoffMultiplier,
             1.0 * (attempt - 1)), maxBackoff.toNanos());
-        if (randomNumberBound <= 0) {
+        if (delayNanos <= 0) {
             return Duration.ZERO;
         }
-        return Duration.ofNanos((long) 
ThreadLocalRandom.current().nextDouble(randomNumberBound));
+        return Duration.ofNanos((long) delayNanos);
     }
 
     @Override

Reply via email to