Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class LoggerBatchProcessor implements ILoggerBatchProcessor {
private volatile @Nullable Future<?> scheduledFlush;
private static final @NotNull AutoClosableReentrantLock scheduleLock =
new AutoClosableReentrantLock();
private volatile boolean hasScheduled = false;

public LoggerBatchProcessor(
final @NotNull SentryOptions options, final @NotNull ISentryClient client) {
Expand Down Expand Up @@ -58,12 +59,16 @@ public void close(final boolean isRestarting) {
}

private void maybeSchedule(boolean forceSchedule, boolean immediately) {
if (hasScheduled && !forceSchedule) {
return;
}
try (final @NotNull ISentryLifecycleToken ignored = scheduleLock.acquire()) {
final @Nullable Future<?> latestScheduledFlush = scheduledFlush;
if (forceSchedule
|| latestScheduledFlush == null
|| latestScheduledFlush.isDone()
|| latestScheduledFlush.isCancelled()) {
hasScheduled = true;
final int flushAfterMs = immediately ? 0 : FLUSH_AFTER_MS;
scheduledFlush = executorService.schedule(new BatchRunnable(), flushAfterMs);
}
Expand All @@ -75,6 +80,8 @@ private void flush() {
try (final @NotNull ISentryLifecycleToken ignored = scheduleLock.acquire()) {
if (!queue.isEmpty()) {
maybeSchedule(true, false);
} else {
hasScheduled = false;
}
}
}
Expand Down
Loading