From f73413e7c04885da497876633e1d7b73d6fb23b6 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 9 Jun 2025 20:26:19 +1000 Subject: [PATCH] Dont deadlock --- .../world/service/SectionSavingService.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java b/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java index 3467761d..809fece3 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java @@ -53,12 +53,18 @@ public class SectionSavingService { //Hard limit the save count to prevent OOM if (this.getTaskCount() > 5_000) { - while (this.getTaskCount() > 5_000) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - throw new RuntimeException(e); + //wait a bit + try { + Thread.sleep(10); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + //If we are still full, process entries in the queue ourselves instead of waiting for the service + while (this.getTaskCount() > 5_000 && this.threads.isAlive()) { + if (!this.threads.steal()) { + break; } + this.processJob(); } }