File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
core/src/main/java/com/microsoft/applicationinsights Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ public class TelemetryClient {
5454 private volatile TelemetryContext context ;
5555 private TelemetryChannel channel ;
5656
57+ private static final Object TELEMETRY_STOP_HOOK_LOCK = new Object ();
5758 private static final Object TELEMETRY_CONTEXT_LOCK = new Object ();
5859
5960 private static AtomicLong generateCounter = new AtomicLong (0 );
@@ -66,6 +67,10 @@ public TelemetryClient(TelemetryConfiguration configuration) {
6667 configuration = TelemetryConfiguration .getActive ();
6768 }
6869
70+ synchronized (TELEMETRY_STOP_HOOK_LOCK ) {
71+ SDKShutdownActivity .INSTANCE .register (configuration .getChannel ());
72+ }
73+
6974 this .configuration = configuration ;
7075 }
7176
@@ -497,7 +502,6 @@ public void flush() {
497502 TelemetryChannel getChannel () {
498503 if (this .channel == null ) {
499504 this .channel = configuration .getChannel ();
500- SDKShutdownActivity .INSTANCE .register (this .channel );
501505 }
502506
503507 return this .channel ;
Original file line number Diff line number Diff line change 2222package com .microsoft .applicationinsights .internal .shutdown ;
2323
2424import java .io .Closeable ;
25+ import java .util .HashMap ;
2526import java .util .List ;
2627import java .util .ArrayList ;
2728import java .util .Map ;
@@ -53,7 +54,7 @@ public enum SDKShutdownActivity {
5354 private static class SDKShutdownAction implements Runnable {
5455 private boolean stopped = false ;
5556
56- private final Map <TelemetryChannel , Boolean > channels = new WeakHashMap <>();
57+ private final Map <TelemetryChannel , Boolean > channels = new HashMap <>();
5758 @ Deprecated
5859 private final List <ChannelFetcher > fetchers = new ArrayList <ChannelFetcher >();
5960 private final List <Stoppable > stoppables = new ArrayList <Stoppable >();
@@ -151,8 +152,9 @@ private void stopChannel(TelemetryChannel channelToStop) {
151152 throw td ;
152153 } catch (Throwable t ) {
153154 try {
154- InternalLogger .INSTANCE .error ("Failed to stop channel: '%s'" , t .toString ());
155- InternalLogger .INSTANCE .trace ("Stack trace generated is %s" , ExceptionUtils .getStackTrace (t ));
155+ if (InternalLogger .INSTANCE .isErrorEnabled ()) {
156+ InternalLogger .INSTANCE .error ("Failed to stop channel: '%s'" , ExceptionUtils .getStackTrace (t ));
157+ }
156158 } catch (ThreadDeath td ) {
157159 throw td ;
158160 } catch (Throwable t2 ) {
You can’t perform that action at this time.
0 commit comments