Skip to content

Commit

Permalink
Switch to shuffle
Browse files Browse the repository at this point in the history
Signed-off-by: Bukhtawar Khan <[email protected]>
  • Loading branch information
Bukhtawar committed Jul 23, 2024
1 parent 5c40c99 commit f5501fa
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,11 +39,11 @@ public BatchRunnableExecutor(List<TimeoutAwareRunnable> 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();
Expand Down

0 comments on commit f5501fa

Please sign in to comment.