Skip to content

Commit a73fd0b

Browse files
committed
Preload a future no-op task to ensure workQueue.take() will use await with timeout during
premain - otherwise on Java 25 it will load ForkJoinPool which in turn loads ForkJoinTask, which then means we lose the chance to field-inject context into ForkJoinTask instances
1 parent ca69374 commit a73fd0b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal-api/src/main/java/datadog/trace/util/AgentTaskScheduler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.util.AgentThreadFactory.AgentThread.TASK_SCHEDULER;
55
import static datadog.trace.util.AgentThreadFactory.newAgentThread;
66
import static java.util.concurrent.TimeUnit.MILLISECONDS;
7+
import static java.util.concurrent.TimeUnit.MINUTES;
78
import static java.util.concurrent.TimeUnit.NANOSECONDS;
89
import static java.util.concurrent.TimeUnit.SECONDS;
910

@@ -225,6 +226,10 @@ private void prepareWorkQueue() {
225226
} catch (final InterruptedException e) {
226227
// ignore, we only want to preload queue internals
227228
}
229+
// preload a future no-op task to ensure workQueue.take() will use await with timeout during
230+
// premain - otherwise on Java 25 it will load ForkJoinPool which in turn loads ForkJoinTask,
231+
// which then means we lose the chance to field-inject context into ForkJoinTask instances
232+
workQueue.offer(FUTURE_NOOP_PLACEHOLDER);
228233
}
229234

230235
// for testing
@@ -302,6 +307,9 @@ public void run() {
302307

303308
private static final AtomicInteger TASK_SEQUENCE_GENERATOR = new AtomicInteger();
304309

310+
private static final PeriodicTask<Object> FUTURE_NOOP_PLACEHOLDER =
311+
new PeriodicTask<>(null, new Scheduled<>(null), 10, 0, MINUTES);
312+
305313
private static final class PeriodicTask<T> implements Delayed {
306314

307315
private final Task<T> task;

0 commit comments

Comments
 (0)