11package io .sentry .logger ;
22
33import io .sentry .ISentryClient ;
4+ import io .sentry .ISentryExecutorService ;
45import io .sentry .ISentryLifecycleToken ;
6+ import io .sentry .SentryExecutorService ;
57import io .sentry .SentryLogEvent ;
68import io .sentry .SentryLogEvents ;
79import io .sentry .SentryOptions ;
@@ -22,6 +24,7 @@ public final class LoggerBatchProcessor implements ILoggerBatchProcessor {
2224 private final @ NotNull SentryOptions options ;
2325 private final @ NotNull ISentryClient client ;
2426 private final @ NotNull Queue <SentryLogEvent > queue ;
27+ private final @ NotNull ISentryExecutorService executorService ;
2528 private volatile @ Nullable Future <?> scheduledFlush ;
2629 private static final @ NotNull AutoClosableReentrantLock scheduleLock =
2730 new AutoClosableReentrantLock ();
@@ -31,6 +34,7 @@ public LoggerBatchProcessor(
3134 this .options = options ;
3235 this .client = client ;
3336 this .queue = new ConcurrentLinkedQueue <>();
37+ this .executorService = new SentryExecutorService ();
3438 }
3539
3640 @ Override
@@ -39,11 +43,14 @@ public void add(final @NotNull SentryLogEvent logEvent) {
3943 maybeSchedule (false , false );
4044 }
4145
46+ @ SuppressWarnings ("FutureReturnValueIgnored" )
4247 @ Override
4348 public void close (final boolean isRestarting ) {
4449 if (isRestarting ) {
4550 maybeSchedule (true , true );
51+ executorService .submit (() -> executorService .close (options .getShutdownTimeoutMillis ()));
4652 } else {
53+ executorService .close (options .getShutdownTimeoutMillis ());
4754 while (!queue .isEmpty ()) {
4855 flushBatch ();
4956 }
@@ -58,7 +65,7 @@ private void maybeSchedule(boolean forceSchedule, boolean immediately) {
5865 || latestScheduledFlush .isDone ()
5966 || latestScheduledFlush .isCancelled ()) {
6067 final int flushAfterMs = immediately ? 0 : FLUSH_AFTER_MS ;
61- scheduledFlush = options . getExecutorService () .schedule (new BatchRunnable (), flushAfterMs );
68+ scheduledFlush = executorService .schedule (new BatchRunnable (), flushAfterMs );
6269 }
6370 }
6471 }
0 commit comments