From 0135c63b882fdc155e030b28ef16cd5c877ab472 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Wed, 7 Aug 2024 02:18:06 +1000 Subject: [PATCH] Attempted last resort fix for thread pool --- .../voxy/common/world/thread/ServiceThreadPool.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java index c2e1eac6..788a36be 100644 --- a/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java @@ -96,8 +96,21 @@ public class ServiceThreadPool { } int attempts = 50; + outer: while (true) { if (attempts-- == 0) { + for (var service : this.serviceSlices) { + //Run the job + if (!service.doRun(threadId)) { + //Didnt consume the job, find a new job + continue; + } + //Consumed a job from the service, decrease weight by the amount + if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) { + throw new IllegalStateException("Total job weight is negative"); + } + break outer; + } throw new IllegalStateException("All attempts at executing a job failed! something critically wrong has occurred"); } seed = (seed ^ seed >>> 30) * -4658895280553007687L;