aboutsummaryrefslogtreecommitdiff
path: root/spark-common
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/ThreadFinder.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/ThreadFinder.java b/spark-common/src/main/java/me/lucko/spark/common/util/ThreadFinder.java
index cc0722a..0d1cbd3 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/util/ThreadFinder.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/util/ThreadFinder.java
@@ -42,7 +42,7 @@ public final class ThreadFinder {
// cache the approx active count at the time of construction.
// the usages of this class are likely to be somewhat short-lived, so it's good
// enough to just cache a value on init.
- private final int approxActiveCount = ROOT_THREAD_GROUP.activeCount();
+ private int approxActiveCount = ROOT_THREAD_GROUP.activeCount();
/**
* Gets a stream of all known active threads.
@@ -50,10 +50,12 @@ public final class ThreadFinder {
* @return a stream of threads
*/
public Stream<Thread> getThreads() {
- Thread[] threads = new Thread[this.approxActiveCount + 20]; // +20 to allow a bit of growth for newly created threads
- while (ROOT_THREAD_GROUP.enumerate(threads, true) == threads.length) {
+ Thread[] threads = new Thread[this.approxActiveCount + 10]; // +10 to allow a bit of growth for newly created threads
+ int len;
+ while ((len = ROOT_THREAD_GROUP.enumerate(threads, true)) == threads.length) {
threads = new Thread[threads.length * 2];
}
+ this.approxActiveCount = len;
return Arrays.stream(threads).filter(Objects::nonNull);
}