@@ -329,8 +329,6 @@ public void run() {
329329 if (appUsingCustomJMXBuilder ) {
330330 log .debug ("Custom JMX builder detected. Delaying JMXFetch initialization." );
331331 registerMBeanServerBuilderCallback (new StartJmxCallback (jmxStartDelay ));
332- // one minute fail-safe in case nothing touches JMX and callback isn't triggered
333- scheduleJmxStart (60 + jmxStartDelay );
334332 } else if (appUsingCustomLogManager ) {
335333 log .debug ("Custom logger detected. Delaying JMXFetch initialization." );
336334 registerLogManagerCallback (new StartJmxCallback (jmxStartDelay ));
@@ -437,6 +435,8 @@ public static void startDatadogTracer(InitializationTelemetry initTelemetry) thr
437435 }
438436
439437 private static void registerLogManagerCallback (final ClassLoadCallBack callback ) {
438+ // one minute fail-safe in case the class was unintentionally loaded during premain
439+ AgentTaskScheduler .INSTANCE .schedule (callback , 1 , TimeUnit .MINUTES );
440440 try {
441441 final Class <?> agentInstallerClass = AGENT_CLASSLOADER .loadClass (AGENT_INSTALLER_CLASS_NAME );
442442 final Method registerCallbackMethod =
@@ -448,6 +448,8 @@ private static void registerLogManagerCallback(final ClassLoadCallBack callback)
448448 }
449449
450450 private static void registerMBeanServerBuilderCallback (final ClassLoadCallBack callback ) {
451+ // one minute fail-safe in case the class was unintentionally loaded during premain
452+ AgentTaskScheduler .INSTANCE .schedule (callback , 1 , TimeUnit .MINUTES );
451453 try {
452454 final Class <?> agentInstallerClass = AGENT_CLASSLOADER .loadClass (AGENT_INSTALLER_CLASS_NAME );
453455 final Method registerCallbackMethod =
@@ -459,8 +461,14 @@ private static void registerMBeanServerBuilderCallback(final ClassLoadCallBack c
459461 }
460462
461463 protected abstract static class ClassLoadCallBack implements Runnable {
464+ private final AtomicBoolean starting = new AtomicBoolean ();
465+
462466 @ Override
463467 public void run () {
468+ if (starting .getAndSet (true )) {
469+ return ; // someone has already called us
470+ }
471+
464472 /*
465473 * This callback is called from within bytecode transformer. This can be a problem if callback tries
466474 * to load classes being transformed. To avoid this we start a thread here that calls the callback.
@@ -558,6 +566,7 @@ public void execute() {
558566 }
559567
560568 private void resumeRemoteComponents () {
569+ log .debug ("Resuming remote components." );
561570 try {
562571 // remote components were paused for custom log-manager/jmx-builder
563572 // add small delay before resuming remote I/O to help stabilization
0 commit comments