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(); } }