Use thread local random.
@@ -18,7 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
/**
* RpcResourcePool constructs {@link FillInvoker} objects that communicate with content nodes over RPC. It also contains
@@ -32,7 +32,6 @@ public class RpcResourcePool extends AbstractComponent {
public final static CompoundName dispatchCompression = new CompoundName("dispatch.compression");
private final Compressor compressor = new Compressor(CompressionType.LZ4, 5, 0.95, 32);
- private final Random random = new Random();
/** Connections to the search nodes this talks to, indexed by node id ("partid") */
private final ImmutableMap<Integer, NodeConnectionPool> nodeConnectionPools;
@@ -90,7 +89,7 @@ public class RpcResourcePool extends AbstractComponent {
}
}
- private class NodeConnectionPool {
+ private static class NodeConnectionPool {
private final List<Client.NodeConnection> connections;
NodeConnectionPool(List<NodeConnection> connections) {
@@ -98,7 +97,7 @@ public class RpcResourcePool extends AbstractComponent {
}
Client.NodeConnection nextConnection() {
- int slot = random.nextInt(connections.size());
+ int slot = ThreadLocalRandom.current().nextInt(connections.size());
return connections.get(slot);
}
