diff --git a/common/src/main/java/org/keycloak/common/util/Retry.java b/common/src/main/java/org/keycloak/common/util/Retry.java
index 05894afb358b..d3225b9b9c6e 100644
--- a/common/src/main/java/org/keycloak/common/util/Retry.java
+++ b/common/src/main/java/org/keycloak/common/util/Retry.java
@@ -18,7 +18,7 @@
package org.keycloak.common.util;
import java.time.Duration;
-import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
/**
* @author Stian Thorgersen
@@ -125,8 +125,8 @@ public static int executeWithBackoff(AdvancedRunnable runnable, ThrowableCallbac
}
}
- private static int computeBackoffInterval(int base, int iteration) {
- return new Random().nextInt(computeIterationBase(base, iteration));
+ public static int computeBackoffInterval(int base, int iteration) {
+ return ThreadLocalRandom.current().nextInt(computeIterationBase(base, iteration));
}
private static int computeIterationBase(int base, int iteration) {
diff --git a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java
index 7f9bc7bd1e84..d0907221d925 100644
--- a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java
+++ b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java
@@ -26,6 +26,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
import org.infinispan.Cache;
import org.infinispan.client.hotrod.RemoteCache;
@@ -36,6 +37,7 @@
import org.infinispan.client.hotrod.event.ClientCacheEntryCreatedEvent;
import org.infinispan.client.hotrod.event.ClientCacheEntryModifiedEvent;
import org.infinispan.client.hotrod.event.ClientCacheEntryRemovedEvent;
+import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.context.Flag;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
@@ -54,7 +56,6 @@
import org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory;
import org.keycloak.executors.ExecutorsProvider;
import org.keycloak.models.KeycloakSession;
-import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import static org.keycloak.cluster.infinispan.InfinispanClusterProvider.TASK_KEY_PREFIX;
@@ -67,13 +68,16 @@ public class InfinispanNotificationsManager {
protected static final Logger logger = Logger.getLogger(InfinispanNotificationsManager.class);
+ private static final int BACKOFF_BASE_MILLIS = 10;
+ private static final int MAX_BACKOFF_RETRIES = 10;
+
private final ConcurrentMultivaluedHashMap listeners = new ConcurrentMultivaluedHashMap<>();
private final ConcurrentMap taskCallbacks = new ConcurrentHashMap<>();
private final Cache workCache;
- private final RemoteCache workRemoteCache;
+ private final RemoteCache