Skip to content

Commit face071

Browse files
committed
Cancel tasks and purge them
1 parent 0e6a1f4 commit face071

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

sentry/src/main/java/io/sentry/SentryExecutorService.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.concurrent.Callable;
55
import java.util.concurrent.CancellationException;
66
import java.util.concurrent.Future;
7+
import java.util.concurrent.RejectedExecutionException;
78
import java.util.concurrent.ScheduledThreadPoolExecutor;
89
import java.util.concurrent.ThreadFactory;
910
import java.util.concurrent.TimeUnit;
@@ -123,17 +124,18 @@ public boolean isClosed() {
123124
public void prewarm() {
124125
executorService.submit(
125126
() -> {
126-
// schedule a bunch of dummy runnables in the future that will never execute to trigger
127-
// queue
128-
// growth and then clear the queue up
129-
for (int i = 0; i < INITIAL_QUEUE_SIZE; i++) {
130-
executorService.schedule(dummyRunnable, Long.MAX_VALUE, TimeUnit.DAYS);
127+
try {
128+
// schedule a bunch of dummy runnables in the future that will never execute to trigger
129+
// queue growth and then purge the queue
130+
for (int i = 0; i < INITIAL_QUEUE_SIZE; i++) {
131+
final Future<?> future = executorService.schedule(dummyRunnable, 365L, TimeUnit.DAYS);
132+
future.cancel(true);
133+
}
134+
executorService.purge();
135+
} catch (RejectedExecutionException ignored) {
136+
// ignore
131137
}
132138
});
133-
executorService.submit(
134-
() -> {
135-
executorService.getQueue().clear();
136-
});
137139
}
138140

139141
private static final class SentryExecutorServiceThreadFactory implements ThreadFactory {

0 commit comments

Comments
 (0)