diff options
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java | 14 | ||||
-rw-r--r-- | spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java | 6 |
2 files changed, 17 insertions, 3 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 fe3a6a7..fd0c413 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 @@ -76,10 +76,24 @@ public interface ThreadDumper { * the game (server/client) thread. */ final class GameThread implements Supplier<ThreadDumper> { + private Supplier<Thread> threadSupplier; private Specific dumper = null; + public GameThread() { + + } + + public GameThread(Supplier<Thread> threadSupplier) { + this.threadSupplier = threadSupplier; + } + @Override public ThreadDumper get() { + if (this.dumper == null) { + setThread(this.threadSupplier.get()); + this.threadSupplier = null; + } + return Objects.requireNonNull(this.dumper, "dumper"); } diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java index 19d0707..0ef6620 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java @@ -59,12 +59,12 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman } private final MinecraftClient minecraft; - private final ThreadDumper gameThreadDumper; + private final ThreadDumper.GameThread gameThreadDumper; public FabricClientSparkPlugin(FabricSparkMod mod, MinecraftClient minecraft) { super(mod); this.minecraft = minecraft; - this.gameThreadDumper = new ThreadDumper.Specific(((MinecraftClientAccessor) minecraft).getThread()); + this.gameThreadDumper = new ThreadDumper.GameThread(() -> ((MinecraftClientAccessor) minecraft).getThread()); } @Override @@ -124,7 +124,7 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman @Override public ThreadDumper getDefaultThreadDumper() { - return this.gameThreadDumper; + return this.gameThreadDumper.get(); } @Override |