Skip to content

Commit f73413e

Browse files
committed
Dont deadlock
1 parent 5b752d3 commit f73413e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ public void enqueueSave(WorldEngine in, WorldSection section) {
5353

5454
//Hard limit the save count to prevent OOM
5555
if (this.getTaskCount() > 5_000) {
56-
while (this.getTaskCount() > 5_000) {
57-
try {
58-
Thread.sleep(10);
59-
} catch (InterruptedException e) {
60-
throw new RuntimeException(e);
56+
//wait a bit
57+
try {
58+
Thread.sleep(10);
59+
} catch (InterruptedException e) {
60+
throw new RuntimeException(e);
61+
}
62+
//If we are still full, process entries in the queue ourselves instead of waiting for the service
63+
while (this.getTaskCount() > 5_000 && this.threads.isAlive()) {
64+
if (!this.threads.steal()) {
65+
break;
6166
}
67+
this.processJob();
6268
}
6369
}
6470

0 commit comments

Comments
 (0)