@@ -329,8 +329,6 @@ public void run() {
329
329
if (appUsingCustomJMXBuilder ) {
330
330
log .debug ("Custom JMX builder detected. Delaying JMXFetch initialization." );
331
331
registerMBeanServerBuilderCallback (new StartJmxCallback (jmxStartDelay ));
332
- // one minute fail-safe in case nothing touches JMX and callback isn't triggered
333
- scheduleJmxStart (60 + jmxStartDelay );
334
332
} else if (appUsingCustomLogManager ) {
335
333
log .debug ("Custom logger detected. Delaying JMXFetch initialization." );
336
334
registerLogManagerCallback (new StartJmxCallback (jmxStartDelay ));
@@ -437,6 +435,8 @@ public static void startDatadogTracer(InitializationTelemetry initTelemetry) thr
437
435
}
438
436
439
437
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 );
440
440
try {
441
441
final Class <?> agentInstallerClass = AGENT_CLASSLOADER .loadClass (AGENT_INSTALLER_CLASS_NAME );
442
442
final Method registerCallbackMethod =
@@ -448,6 +448,8 @@ private static void registerLogManagerCallback(final ClassLoadCallBack callback)
448
448
}
449
449
450
450
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 );
451
453
try {
452
454
final Class <?> agentInstallerClass = AGENT_CLASSLOADER .loadClass (AGENT_INSTALLER_CLASS_NAME );
453
455
final Method registerCallbackMethod =
@@ -459,8 +461,14 @@ private static void registerMBeanServerBuilderCallback(final ClassLoadCallBack c
459
461
}
460
462
461
463
protected abstract static class ClassLoadCallBack implements Runnable {
464
+ private final AtomicBoolean starting = new AtomicBoolean ();
465
+
462
466
@ Override
463
467
public void run () {
468
+ if (starting .getAndSet (true )) {
469
+ return ; // someone has already called us
470
+ }
471
+
464
472
/*
465
473
* This callback is called from within bytecode transformer. This can be a problem if callback tries
466
474
* to load classes being transformed. To avoid this we start a thread here that calls the callback.
@@ -558,6 +566,7 @@ public void execute() {
558
566
}
559
567
560
568
private void resumeRemoteComponents () {
569
+ log .debug ("Resuming remote components." );
561
570
try {
562
571
// remote components were paused for custom log-manager/jmx-builder
563
572
// add small delay before resuming remote I/O to help stabilization
0 commit comments