From f5501fae79c59dd0d6e2d46a5db94aad412971ff Mon Sep 17 00:00:00 2001 From: Bukhtawar Khan Date: Tue, 23 Jul 2024 12:56:11 +0530 Subject: [PATCH] Switch to shuffle Signed-off-by: Bukhtawar Khan --- .../java/org/opensearch/common/util/BatchRunnableExecutor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/common/util/BatchRunnableExecutor.java b/server/src/main/java/org/opensearch/common/util/BatchRunnableExecutor.java index 014f13091b6b8..4e9d35cafd67d 100644 --- a/server/src/main/java/org/opensearch/common/util/BatchRunnableExecutor.java +++ b/server/src/main/java/org/opensearch/common/util/BatchRunnableExecutor.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.common.Randomness; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.TimeoutAwareRunnable; import org.opensearch.core.common.util.CollectionUtils; @@ -38,11 +39,11 @@ public BatchRunnableExecutor(List timeoutAwareRunnables, S @Override public void run() { logger.debug("Starting execution of runnable of size [{}]", timeoutAwareRunnables.size()); - Collections.shuffle(timeoutAwareRunnables); long startTime = System.nanoTime(); if (CollectionUtils.isEmpty(timeoutAwareRunnables)) { return; } + Randomness.shuffle(timeoutAwareRunnables); for (TimeoutAwareRunnable workQueue : timeoutAwareRunnables) { if (timeoutSupplier.get().nanos() < 0 || System.nanoTime() - startTime < timeoutSupplier.get().nanos()) { workQueue.run();