diff --git a/CHANGELOG.md b/CHANGELOG.md index 5516d3c991..d7cedbaa41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,8 @@ ### Fixes - Finish WebFlux transaction before popping scope ([#2724](https://github.com/getsentry/sentry-java/pull/2724)) - -### Fixes - +- Use daemon threads for SentryExecutorService ([#2747](https://github.com/getsentry/sentry-java/pull/2747)) + - We started using `SentryExecutorService` in `6.19.0` which caused the application to hang on shutdown unless `Sentry.close()` was called. By using daemon threads we no longer block shutdown. - Use Base64.NO_WRAP to avoid unexpected char errors in Apollo ([#2745](https://github.com/getsentry/sentry-java/pull/2745)) - Don't warn R8 on missing `ComposeViewHierarchyExporter` class ([#2743](https://github.com/getsentry/sentry-java/pull/2743)) diff --git a/sentry/src/main/java/io/sentry/SentryExecutorService.java b/sentry/src/main/java/io/sentry/SentryExecutorService.java index ba0ae4fac5..9097cb7fdc 100644 --- a/sentry/src/main/java/io/sentry/SentryExecutorService.java +++ b/sentry/src/main/java/io/sentry/SentryExecutorService.java @@ -4,6 +4,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -18,7 +19,7 @@ final class SentryExecutorService implements ISentryExecutorService { } SentryExecutorService() { - this(Executors.newSingleThreadScheduledExecutor()); + this(Executors.newSingleThreadScheduledExecutor(new SentryExecutorServiceThreadFactory())); } @Override @@ -59,4 +60,15 @@ public boolean isClosed() { return executorService.isShutdown(); } } + + private static final class SentryExecutorServiceThreadFactory implements ThreadFactory { + private int cnt; + + @Override + public @NotNull Thread newThread(final @NotNull Runnable r) { + final Thread ret = new Thread(r, "SentryExecutorServiceThreadFactory-" + cnt++); + ret.setDaemon(true); + return ret; + } + } }