From 1443e5c44c1e25896d5df55f5973f22efc99f7e1 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:05:31 +0100 Subject: [PATCH] ref: changed to static reference --- .../signalbox/config/SignalConfig.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index a8e9fe626..d8523e697 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -26,8 +26,8 @@ public final class SignalConfig { private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( SignalConfig.class); + private static final ExecutorService SERVICE = Executors.newCachedThreadPool(); - private final ExecutorService service = Executors.newCachedThreadPool(); private final SignalBoxPathway pathway; public SignalConfig(final SignalBoxPathway pathway) { @@ -53,7 +53,7 @@ public void change(final ConfigInfo info) { final List shuntingValues = OneSignalNonPredicateConfigParser.SHUNTINGCONFIGS .get(currentSignal); if (shuntingValues != null && info.currentinfo.isValid()) { - service.execute(() -> loadWithoutPredicate(shuntingValues, info.currentinfo)); + loadWithoutPredicate(shuntingValues, info.currentinfo); } } } @@ -100,16 +100,14 @@ public void loadDisable(final ConfigInfo info) { } private void changeIfPresent(final List values, final ConfigInfo info) { - service.execute(() -> { - loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { - if (info.nextinfo != null) { - loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { - changeSignals(values, info, oldProperties, nextProperties); - }); - } else { - changeSignals(values, info, oldProperties, null); - } - }); + loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { + if (info.nextinfo != null) { + loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { + changeSignals(values, info, oldProperties, nextProperties); + }); + } else { + changeSignals(values, info, oldProperties, null); + } }); } @@ -155,12 +153,14 @@ private void loadWithoutPredicate(final List values, private static void loadSignalAndRunTask(final SignalStateInfo info, final SignalStateListener task) { - final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); - if (!isSignalLoaded) { - SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); - task.andThen((_u1, _u2, _u3) -> SignalStateHandler - .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); - } - SignalStateHandler.runTaskWhenSignalLoaded(info, task); + SERVICE.execute(() -> { + final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); + if (!isSignalLoaded) { + SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); + task.andThen((_u1, _u2, _u3) -> SignalStateHandler + .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); + } + SignalStateHandler.runTaskWhenSignalLoaded(info, task); + }); } }