Skip to content

Commit d528048

Browse files
authored
Use daemon threads for SentryExecutorService (#2747)
1 parent f0c28a1 commit d528048

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
### Fixes
1313

1414
- Finish WebFlux transaction before popping scope ([#2724](https://github.com/getsentry/sentry-java/pull/2724))
15-
16-
### Fixes
17-
15+
- Use daemon threads for SentryExecutorService ([#2747](https://github.com/getsentry/sentry-java/pull/2747))
16+
- 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.
1817
- Use Base64.NO_WRAP to avoid unexpected char errors in Apollo ([#2745](https://github.com/getsentry/sentry-java/pull/2745))
1918
- Don't warn R8 on missing `ComposeViewHierarchyExporter` class ([#2743](https://github.com/getsentry/sentry-java/pull/2743))
2019

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.concurrent.Executors;
55
import java.util.concurrent.Future;
66
import java.util.concurrent.ScheduledExecutorService;
7+
import java.util.concurrent.ThreadFactory;
78
import java.util.concurrent.TimeUnit;
89
import org.jetbrains.annotations.NotNull;
910
import org.jetbrains.annotations.TestOnly;
@@ -18,7 +19,7 @@ final class SentryExecutorService implements ISentryExecutorService {
1819
}
1920

2021
SentryExecutorService() {
21-
this(Executors.newSingleThreadScheduledExecutor());
22+
this(Executors.newSingleThreadScheduledExecutor(new SentryExecutorServiceThreadFactory()));
2223
}
2324

2425
@Override
@@ -59,4 +60,15 @@ public boolean isClosed() {
5960
return executorService.isShutdown();
6061
}
6162
}
63+
64+
private static final class SentryExecutorServiceThreadFactory implements ThreadFactory {
65+
private int cnt;
66+
67+
@Override
68+
public @NotNull Thread newThread(final @NotNull Runnable r) {
69+
final Thread ret = new Thread(r, "SentryExecutorServiceThreadFactory-" + cnt++);
70+
ret.setDaemon(true);
71+
return ret;
72+
}
73+
}
6274
}

0 commit comments

Comments
 (0)