diff options
author | Luck <git@lucko.me> | 2021-03-27 18:51:20 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2021-03-27 18:51:31 +0000 |
commit | a3129bc834bf22b89f7ac545a960b89361b03459 (patch) | |
tree | ded73116fb2e775b24f229b01e891194b41d24b3 /spark-common/src/main/java/me/lucko/spark/common/sampler | |
parent | da2b2e3d948e7533379f039a6686d2b5e3722047 (diff) | |
download | spark-a3129bc834bf22b89f7ac545a960b89361b03459.tar.gz spark-a3129bc834bf22b89f7ac545a960b89361b03459.tar.bz2 spark-a3129bc834bf22b89f7ac545a960b89361b03459.zip |
Execute commands async
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/sampler')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index 4863482..e99114a 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import java.util.stream.Collectors; @@ -72,6 +73,25 @@ public interface ThreadDumper { }; /** + * Utility to cache the creation of a {@link ThreadDumper} targeting + * the game (server/client) thread. + */ + final class GameThread implements Supplier<ThreadDumper> { + private Specific dumper = null; + + @Override + public ThreadDumper get() { + return Objects.requireNonNull(this.dumper, "dumper"); + } + + public void ensureSetup() { + if (this.dumper == null) { + this.dumper = new Specific(new long[]{Thread.currentThread().getId()}); + } + } + } + + /** * Implementation of {@link ThreadDumper} that generates data for a specific set of threads. */ final class Specific implements ThreadDumper { |