1
1
package io .sentry .logger ;
2
2
3
3
import io .sentry .ISentryClient ;
4
+ import io .sentry .ISentryExecutorService ;
4
5
import io .sentry .ISentryLifecycleToken ;
6
+ import io .sentry .SentryExecutorService ;
5
7
import io .sentry .SentryLogEvent ;
6
8
import io .sentry .SentryLogEvents ;
7
9
import io .sentry .SentryOptions ;
@@ -22,6 +24,7 @@ public final class LoggerBatchProcessor implements ILoggerBatchProcessor {
22
24
private final @ NotNull SentryOptions options ;
23
25
private final @ NotNull ISentryClient client ;
24
26
private final @ NotNull Queue <SentryLogEvent > queue ;
27
+ private final @ NotNull ISentryExecutorService executorService ;
25
28
private volatile @ Nullable Future <?> scheduledFlush ;
26
29
private static final @ NotNull AutoClosableReentrantLock scheduleLock =
27
30
new AutoClosableReentrantLock ();
@@ -31,6 +34,7 @@ public LoggerBatchProcessor(
31
34
this .options = options ;
32
35
this .client = client ;
33
36
this .queue = new ConcurrentLinkedQueue <>();
37
+ this .executorService = new SentryExecutorService ();
34
38
}
35
39
36
40
@ Override
@@ -39,11 +43,14 @@ public void add(final @NotNull SentryLogEvent logEvent) {
39
43
maybeSchedule (false , false );
40
44
}
41
45
46
+ @ SuppressWarnings ("FutureReturnValueIgnored" )
42
47
@ Override
43
48
public void close (final boolean isRestarting ) {
44
49
if (isRestarting ) {
45
50
maybeSchedule (true , true );
51
+ executorService .submit (() -> executorService .close (options .getShutdownTimeoutMillis ()));
46
52
} else {
53
+ executorService .close (options .getShutdownTimeoutMillis ());
47
54
while (!queue .isEmpty ()) {
48
55
flushBatch ();
49
56
}
@@ -58,7 +65,7 @@ private void maybeSchedule(boolean forceSchedule, boolean immediately) {
58
65
|| latestScheduledFlush .isDone ()
59
66
|| latestScheduledFlush .isCancelled ()) {
60
67
final int flushAfterMs = immediately ? 0 : FLUSH_AFTER_MS ;
61
- scheduledFlush = options . getExecutorService () .schedule (new BatchRunnable (), flushAfterMs );
68
+ scheduledFlush = executorService .schedule (new BatchRunnable (), flushAfterMs );
62
69
}
63
70
}
64
71
}
0 commit comments