From bca07d60af045fbbc725e5aba847d163f7356e12 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 20 Oct 2024 23:31:45 +0200 Subject: [PATCH] ref: maby better load System for Names and Signals --- .../java/com/troblecodings/signals/handler/NameHandler.java | 5 +++-- .../troblecodings/signals/handler/SignalStateHandler.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/handler/NameHandler.java b/src/main/java/com/troblecodings/signals/handler/NameHandler.java index 7fed823c7..44dfd829e 100644 --- a/src/main/java/com/troblecodings/signals/handler/NameHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/NameHandler.java @@ -53,6 +53,7 @@ public final class NameHandler implements INetworkSync { private static ExecutorService writeService = Executors.newFixedThreadPool(5); + private static final ExecutorService readService = Executors.newCachedThreadPool(); private static final Map ALL_NAMES = new HashMap<>(); private static final Map ALL_LEVEL_FILES = new HashMap<>(); private static final Map> TASKS_WHEN_LOAD = new HashMap<>(); @@ -322,7 +323,7 @@ public static void loadNames(final List infos, final @Nullable EntityPlayer player) { if (infos == null || infos.isEmpty()) return; - new Thread(() -> { + readService.execute(() -> { infos.forEach(info -> { boolean isLoaded = false; synchronized (LOAD_COUNTER) { @@ -368,7 +369,7 @@ public static void loadNames(final List infos, } } }); - }, "OSNameHandler:loadNames").start(); + }); } public static void unloadName(final StateLoadHolder holder) { diff --git a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java index 457b1bd3d..15c851ffe 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java @@ -56,6 +56,7 @@ private SignalStateHandler() { } private static ExecutorService writeService = Executors.newFixedThreadPool(5); + private static final ExecutorService readService = Executors.newCachedThreadPool(); private static final Map> CURRENTLY_LOADED_STATES = new HashMap<>(); private static final Map ALL_LEVEL_FILES = new HashMap<>(); private static final Map>> SIGNAL_COUNTER = new HashMap<>(); @@ -532,7 +533,7 @@ public static void loadSignals(final List signals, final @Nullable EntityPlayer player) { if (signals == null || signals.isEmpty()) return; - new Thread(() -> { + readService.execute(() -> { signals.forEach(info -> { boolean isLoaded = false; synchronized (SIGNAL_COUNTER) { @@ -567,7 +568,7 @@ public static void loadSignals(final List signals, } } }); - }, "OSSignalStateHandler:loadSignals").start(); + }); } public static void unloadSignal(final SignalStateLoadHoler info) {