2828import java .util .Collection ;
2929import java .util .List ;
3030import java .util .Map ;
31- import java .util .Random ;
3231import java .util .concurrent .Callable ;
3332import java .util .concurrent .ExecutionException ;
3433import java .util .concurrent .ExecutorService ;
3534import java .util .concurrent .Future ;
3635import java .util .concurrent .ThreadFactory ;
36+ import java .util .concurrent .ThreadLocalRandom ;
3737import java .util .concurrent .ThreadPoolExecutor ;
3838import java .util .concurrent .TimeUnit ;
3939import java .util .concurrent .TimeoutException ;
@@ -65,7 +65,6 @@ public class OrderedExecutor implements ExecutorService {
6565 final String name ;
6666 final ExecutorService [] threads ;
6767 final long [] threadIds ;
68- final Random rand = new Random ();
6968 final OpStatsLogger taskExecutionStats ;
7069 final OpStatsLogger taskPendingStats ;
7170 final boolean traceTaskExecution ;
@@ -545,7 +544,7 @@ public ExecutorService chooseThread() {
545544 return threads [0 ];
546545 }
547546
548- return threads [rand .nextInt (threads .length )];
547+ return threads [ThreadLocalRandom . current () .nextInt (threads .length )];
549548 }
550549
551550 public ExecutorService chooseThread (Object orderingKey ) {
@@ -555,7 +554,7 @@ public ExecutorService chooseThread(Object orderingKey) {
555554 }
556555
557556 if (null == orderingKey ) {
558- return threads [rand .nextInt (threads .length )];
557+ return threads [ThreadLocalRandom . current () .nextInt (threads .length )];
559558 } else {
560559 return threads [chooseThreadIdx (orderingKey .hashCode (), threads .length )];
561560 }
0 commit comments