Skip to content

Commit defba33

Browse files
authored
[Logs 5] Use a separate ExecutorService for log batching (#4379)
* Add Log feature to Java SDK * Rate limit for log items * Add options for logs * Add batch processor for logs * Use a separate ExecutorService for log batching
1 parent 55564f6 commit defba33

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sentry/src/main/java/io/sentry/logger/LoggerBatchProcessor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.sentry.logger;
22

33
import io.sentry.ISentryClient;
4+
import io.sentry.ISentryExecutorService;
45
import io.sentry.ISentryLifecycleToken;
6+
import io.sentry.SentryExecutorService;
57
import io.sentry.SentryLogEvent;
68
import io.sentry.SentryLogEvents;
79
import 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

Comments
 (0)