aboutsummaryrefslogtreecommitdiffstats
path: root/jaxrs_client_utils
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@oath.com>2018-12-20 14:08:42 +0100
committerHåkon Hallingstad <hakon@oath.com>2018-12-20 14:08:42 +0100
commit9922b4a419ecad5c9d4ea9e351f5e66e55fad84b (patch)
tree32abad6efa16653bacd5caaf559d456c3222a12e /jaxrs_client_utils
parent58e87745267e02e051f6311024dc2fe980ec03a5 (diff)
ThreadLocalRandom is recommended over Random in multithreaded environments, try 2
Diffstat (limited to 'jaxrs_client_utils')
-rw-r--r--jaxrs_client_utils/src/main/java/com/yahoo/vespa/jaxrs/client/JaxRsStrategyFactory.java6
1 files changed, 2 insertions, 4 deletions
diff --git a/jaxrs_client_utils/src/main/java/com/yahoo/vespa/jaxrs/client/JaxRsStrategyFactory.java b/jaxrs_client_utils/src/main/java/com/yahoo/vespa/jaxrs/client/JaxRsStrategyFactory.java
index 1459024767d..9dbc472f4e2 100644
--- a/jaxrs_client_utils/src/main/java/com/yahoo/vespa/jaxrs/client/JaxRsStrategyFactory.java
+++ b/jaxrs_client_utils/src/main/java/com/yahoo/vespa/jaxrs/client/JaxRsStrategyFactory.java
@@ -7,8 +7,8 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
-import java.util.Random;
import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
/**
* The idea behind this class is twofold:
@@ -66,10 +66,8 @@ public class JaxRsStrategyFactory {
return new NoRetryJaxRsStrategy<T>(hostName, port, jaxRsClientFactory, apiClass, pathPrefix, scheme);
}
- private static final Random random = new Random();
-
private static <T> T getRandom(final Collection<? extends T> collection) {
- int index = random.nextInt(collection.size());
+ int index = ThreadLocalRandom.current().nextInt(collection.size());
return getIndex(collection, index);
}