aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/sampler
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2018-11-04 01:05:41 +0000
committerLuck <git@lucko.me>2018-11-04 01:05:41 +0000
commit320d6a28b60873c8e8163b27ed1389978aed4ee6 (patch)
treeba130d567e58883458411d115a6eac1b8688220a /spark-common/src/main/java/me/lucko/spark/sampler
parent9e4c0edc47707fbcad34305b3cd723b08f1ab4d6 (diff)
downloadspark-320d6a28b60873c8e8163b27ed1389978aed4ee6.tar.gz
spark-320d6a28b60873c8e8163b27ed1389978aed4ee6.tar.bz2
spark-320d6a28b60873c8e8163b27ed1389978aed4ee6.zip
some misc refactoring
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/sampler')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/sampler/Sampler.java4
-rw-r--r--spark-common/src/main/java/me/lucko/spark/sampler/ThreadDumper.java9
-rw-r--r--spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java19
3 files changed, 8 insertions, 24 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 7ad7e7b..5758d85 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
@@ -99,7 +99,7 @@ public class Sampler implements Runnable {
public void start() {
this.startTime = System.currentTimeMillis();
this.dataAggregator.start();
- this.task = workerPool.scheduleAtFixedRate(this, 0, interval, TimeUnit.MILLISECONDS);
+ this.task = this.workerPool.scheduleAtFixedRate(this, 0, this.interval, TimeUnit.MILLISECONDS);
}
public long getStartTime() {
@@ -118,7 +118,7 @@ public class Sampler implements Runnable {
}
public void cancel() {
- task.cancel(false);
+ this.task.cancel(false);
}
@Override
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 af963c6..940b1c6 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
@@ -44,14 +44,7 @@ public interface ThreadDumper {
/**
* Implementation of {@link ThreadDumper} that generates data for all threads.
*/
- ThreadDumper ALL = new All();
-
- final class All implements ThreadDumper {
- @Override
- public ThreadInfo[] dumpThreads(ThreadMXBean threadBean) {
- return threadBean.dumpAllThreads(false, false);
- }
- }
+ ThreadDumper ALL = threadBean -> threadBean.dumpAllThreads(false, false);
/**
* Implementation of {@link ThreadDumper} that generates data for a specific set of threads.
diff --git a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java
index 0707df6..72cd4dc 100644
--- a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java
+++ b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java
@@ -40,33 +40,24 @@ public interface ThreadGrouper {
/**
* Implementation of {@link ThreadGrouper} that just groups by thread name.
*/
- ThreadGrouper BY_NAME = new ByName();
-
- final class ByName implements ThreadGrouper {
- @Override
- public String getGroup(String threadName) {
- return threadName;
- }
- }
+ ThreadGrouper BY_NAME = threadName -> threadName;
/**
* Implementation of {@link ThreadGrouper} that attempts to group by the name of the pool
* the thread originated from.
*/
- ThreadGrouper BY_POOL = new ByPool();
-
- final class ByPool implements ThreadGrouper {
- private static final Pattern THREAD_POOL_PATTERN = Pattern.compile("^(.*)[-#] ?\\d+$");
+ ThreadGrouper BY_POOL = new ThreadGrouper() {
+ private final Pattern pattern = Pattern.compile("^(.*)[-#] ?\\d+$");
@Override
public String getGroup(String threadName) {
- Matcher matcher = THREAD_POOL_PATTERN.matcher(threadName);
+ Matcher matcher = this.pattern.matcher(threadName);
if (!matcher.matches()) {
return threadName;
}
return matcher.group(1).trim() + " (Combined)";
}
- }
+ };
}