fix deadlock when closing pregen method while using modified concurrency

This commit is contained in:
Julian Krings 2025-04-13 00:13:26 +02:00 committed by Julian Krings
parent a10a784c3b
commit c00dcf205b

View File

@ -42,6 +42,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
private final World world; private final World world;
private final ExecutorService service; private final ExecutorService service;
private final Semaphore semaphore; private final Semaphore semaphore;
private final int threads;
private final Map<Chunk, Long> lastUse; private final Map<Chunk, Long> lastUse;
public AsyncPregenMethod(World world, int threads) { public AsyncPregenMethod(World world, int threads) {
@ -53,7 +54,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
service = IrisSettings.get().getPregen().isUseVirtualThreads() ? service = IrisSettings.get().getPregen().isUseVirtualThreads() ?
Executors.newVirtualThreadPerTaskExecutor() : Executors.newVirtualThreadPerTaskExecutor() :
new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY); new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY);
semaphore = new Semaphore(IrisSettings.get().getPregen().getMaxConcurrency()); this.threads = IrisSettings.get().getPregen().getMaxConcurrency();
semaphore = new Semaphore(threads);
this.lastUse = new KMap<>(); this.lastUse = new KMap<>();
} }
@ -106,7 +108,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
@Override @Override
public void close() { public void close() {
semaphore.acquireUninterruptibly(256); semaphore.acquireUninterruptibly(threads);
unloadAndSaveAllChunks(); unloadAndSaveAllChunks();
service.shutdown(); service.shutdown();
} }