Skip to content

Commit 5deca0c

Browse files
committed
Inline the scheduling of the snapshot thread profiling into the 'computeIfAbsent' mapping function.
1 parent eaece87 commit 5deca0c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

profiler/src/main/java/com/splunk/opentelemetry/profiler/snapshot/ScheduledExecutorStackTraceSampler.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,17 @@ class ScheduledExecutorStackTraceSampler implements StackTraceSampler {
5757

5858
@Override
5959
public void start(SpanContext spanContext) {
60-
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
61-
ScheduledExecutorService mappedScheduler =
62-
samplers.computeIfAbsent(spanContext.getTraceId(), id -> scheduler);
63-
if (scheduler == mappedScheduler) {
64-
scheduler.scheduleAtFixedRate(
65-
new StackTraceGatherer(spanContext.getTraceId(), Thread.currentThread().getId()),
66-
SCHEDULER_INITIAL_DELAY,
67-
samplingPeriod.toMillis(),
68-
TimeUnit.MILLISECONDS);
69-
} else {
70-
scheduler.shutdown();
71-
}
60+
samplers.computeIfAbsent(
61+
spanContext.getTraceId(),
62+
traceId -> {
63+
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
64+
scheduler.scheduleAtFixedRate(
65+
new StackTraceGatherer(traceId, Thread.currentThread().getId()),
66+
SCHEDULER_INITIAL_DELAY,
67+
samplingPeriod.toMillis(),
68+
TimeUnit.MILLISECONDS);
69+
return scheduler;
70+
});
7271
}
7372

7473
@Override

0 commit comments

Comments
 (0)