aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2019-01-21 13:19:25 +0000
committerLuck <git@lucko.me>2019-01-21 13:19:25 +0000
commit974dc793c3d9c4811958643ca50668f3cb85b1ff (patch)
tree154b4756c0ebd41bddd3f8de999c70b429239bf6 /spark-common/src/main/java/me/lucko/spark
parent788a61af26563f6f0d73b47c64d1bf8f6547997d (diff)
downloadspark-974dc793c3d9c4811958643ca50668f3cb85b1ff.tar.gz
spark-974dc793c3d9c4811958643ca50668f3cb85b1ff.tar.bz2
spark-974dc793c3d9c4811958643ca50668f3cb85b1ff.zip
Refactor ThreadDumper#dumpThreads return value
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java3
-rw-r--r--spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java13
2 files changed, 7 insertions, 9 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java b/spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java
index d78b3fd..3a9a271 100644
--- a/spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java
@@ -23,7 +23,6 @@ package me.lucko.spark.sampler;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.stream.JsonWriter;
-
import me.lucko.spark.sampler.aggregator.DataAggregator;
import me.lucko.spark.sampler.aggregator.SimpleDataAggregator;
import me.lucko.spark.sampler.aggregator.TickedDataAggregator;
@@ -130,7 +129,7 @@ public class Sampler implements Runnable {
return;
}
- Iterable<ThreadInfo> threadDumps = this.threadDumper.dumpThreads(this.threadBean);
+ ThreadInfo[] threadDumps = this.threadDumper.dumpThreads(this.threadBean);
for (ThreadInfo threadInfo : threadDumps) {
String threadName = threadInfo.getThreadName();
StackTraceElement[] stack = threadInfo.getStackTrace();
diff --git a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java
index 38cdd36..5b68eaf 100644
--- a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java
+++ b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java
@@ -25,7 +25,6 @@ import me.lucko.spark.util.ThreadFinder;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -47,12 +46,12 @@ public interface ThreadDumper {
* @param threadBean the thread bean instance to obtain the data from
* @return an array of generated thread info instances
*/
- Iterable<ThreadInfo> dumpThreads(ThreadMXBean threadBean);
+ ThreadInfo[] dumpThreads(ThreadMXBean threadBean);
/**
* Implementation of {@link ThreadDumper} that generates data for all threads.
*/
- ThreadDumper ALL = threadBean -> Arrays.asList(threadBean.dumpAllThreads(false, false));
+ ThreadDumper ALL = threadBean -> threadBean.dumpAllThreads(false, false);
/**
* Implementation of {@link ThreadDumper} that generates data for a specific set of threads.
@@ -74,8 +73,8 @@ public interface ThreadDumper {
}
@Override
- public Iterable<ThreadInfo> dumpThreads(ThreadMXBean threadBean) {
- return Arrays.asList(threadBean.getThreadInfo(this.ids, Integer.MAX_VALUE));
+ public ThreadInfo[] dumpThreads(ThreadMXBean threadBean) {
+ return threadBean.getThreadInfo(this.ids, Integer.MAX_VALUE);
}
}
@@ -101,7 +100,7 @@ public interface ThreadDumper {
}
@Override
- public Iterable<ThreadInfo> dumpThreads(ThreadMXBean threadBean) {
+ public ThreadInfo[] dumpThreads(ThreadMXBean threadBean) {
return this.threadFinder.getThreads()
.filter(thread -> {
Boolean result = this.cache.get(thread.getId());
@@ -120,7 +119,7 @@ public interface ThreadDumper {
})
.map(thread -> threadBean.getThreadInfo(thread.getId()))
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toArray(ThreadInfo[]::new);
}
}