Skip to content

Commit eb5dc6f

Browse files
brunobatrobsunday
authored andcommitted
Fix native mode error cause by static init of random (open-telemetry#862)
1 parent 5ffa348 commit eb5dc6f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSampler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.Executors;
2929
import java.util.concurrent.ScheduledExecutorService;
3030
import java.util.concurrent.ScheduledFuture;
31+
import java.util.concurrent.ThreadLocalRandom;
3132
import java.util.concurrent.TimeUnit;
3233
import java.util.function.Function;
3334
import java.util.logging.Level;
@@ -40,7 +41,6 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {
4041

4142
static final long DEFAULT_TARGET_INTERVAL_NANOS = TimeUnit.SECONDS.toNanos(10);
4243

43-
private static final Random RANDOM = new Random();
4444
private static final Logger logger = Logger.getLogger(AwsXrayRemoteSampler.class.getName());
4545

4646
private final Resource resource;
@@ -97,7 +97,7 @@ public static AwsXrayRemoteSamplerBuilder newBuilder(Resource resource) {
9797

9898
this.pollingIntervalNanos = pollingIntervalNanos;
9999
// Add ~1% of jitter
100-
jitterNanos = RANDOM.longs(0, pollingIntervalNanos / 100).iterator();
100+
jitterNanos = ThreadLocalRandom.current().longs(0, pollingIntervalNanos / 100).iterator();
101101

102102
// Execute first update right away on the executor thread.
103103
executor.execute(this::getAndUpdateSampler);

0 commit comments

Comments
 (0)