This is an automated email from the ASF dual-hosted git repository. merlimat pushed a commit to branch branch-4.18 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit 15e1bf2f14cdba58d5945f3e2e81c38f7ddfff85 Author: Matteo Merli <[email protected]> AuthorDate: Tue Jul 14 08:25:38 2026 -0700 Use ThreadLocalRandom for thread selection in OrderedExecutor (#4832) (cherry picked from commit 970f56ea0416e208cac1ea6b8d923b7ae8060adc) --- .../java/org/apache/bookkeeper/common/util/OrderedExecutor.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java index 516581fdb0..f32d25c3ce 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java @@ -28,12 +28,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -65,7 +65,6 @@ public class OrderedExecutor implements ExecutorService { final String name; final ExecutorService[] threads; final long[] threadIds; - final Random rand = new Random(); final OpStatsLogger taskExecutionStats; final OpStatsLogger taskPendingStats; final boolean traceTaskExecution; @@ -545,7 +544,7 @@ public class OrderedExecutor implements ExecutorService { return threads[0]; } - return threads[rand.nextInt(threads.length)]; + return threads[ThreadLocalRandom.current().nextInt(threads.length)]; } public ExecutorService chooseThread(Object orderingKey) { @@ -555,7 +554,7 @@ public class OrderedExecutor implements ExecutorService { } if (null == orderingKey) { - return threads[rand.nextInt(threads.length)]; + return threads[ThreadLocalRandom.current().nextInt(threads.length)]; } else { return threads[chooseThreadIdx(orderingKey.hashCode(), threads.length)]; }
