From eeb2c68c8775d4bbe9ae0a74ba98283828c67af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Chavarr=C3=ADa?= <89037579+Txaverria@users.noreply.github.com> Date: Sun, 9 Aug 2026 22:17:17 -0600 Subject: [PATCH] Prevent custom tick threads from blocking shutdown --- .../theimpossiblelibrary/api/util/CustomTick.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/mods/thecomputerizer/theimpossiblelibrary/api/util/CustomTick.java b/api/src/main/java/mods/thecomputerizer/theimpossiblelibrary/api/util/CustomTick.java index adbeea9c1..473339dfc 100644 --- a/api/src/main/java/mods/thecomputerizer/theimpossiblelibrary/api/util/CustomTick.java +++ b/api/src/main/java/mods/thecomputerizer/theimpossiblelibrary/api/util/CustomTick.java @@ -9,6 +9,8 @@ import java.util.List; import java.util.Objects; import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -16,11 +18,18 @@ public class CustomTick { private static final List registeredTickEvents = new ArrayList<>(); + private static final AtomicInteger threadCounter = new AtomicInteger(); + private static final ThreadFactory threadFactory = runnable -> { + Thread thread = new Thread(runnable,"TIL-CustomTick-"+threadCounter.incrementAndGet()); + // Custom ticks live for the process lifetime and must not prevent the JVM from shutting down. + thread.setDaemon(true); + return thread; + }; private static void addCustomTick(final CustomTick ticker) { CommonEventsAPI api = EventHelper.getEventsAPI(false,false); if(Objects.isNull(api) || isRegistered(ticker)) return; - Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> { + Executors.newScheduledThreadPool(1,threadFactory).scheduleAtFixedRate(() -> { try { api.postCustomTick(ticker); } catch(Throwable t) {