From 917e308ece7cd3980db9305f3efd480099950970 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Fri, 2 May 2025 23:44:12 +1000 Subject: [PATCH] releaseNow when trying to shutdown service --- .../cortex/voxy/common/thread/ServiceThreadPool.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java index e8d198e3..9f12a46f 100644 --- a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java @@ -24,6 +24,7 @@ public class ServiceThreadPool { } private volatile boolean running = true; + private volatile boolean releaseNow = false; private Thread[] workers = new Thread[0]; private final Semaphore jobCounter = new Semaphore(0); @@ -129,9 +130,11 @@ public class ServiceThreadPool { void steal(ServiceSlice service, int count) { this.totalJobWeight.addAndGet(-(service.weightPerJob*(long)count)); + this.releaseNow = true; for (int i = 0; i < count; i++) { this.jobCounter.acquireUninterruptibly(); } + this.releaseNow = false; } private void worker(int threadId) { @@ -157,6 +160,15 @@ public class ServiceThreadPool { throw new RuntimeException(e); } } + if (this.releaseNow) { + this.jobCounter.release(); + try { + Thread.sleep(20); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + break; + } var ref = this.serviceSlices; if (ref.length == 0) { Logger.error("Service worker tried to run but had 0 slices");