diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/PriorityTaskPicker.java b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/PriorityTaskPicker.java index 61e39e290..91b5a34d2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/PriorityTaskPicker.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/PriorityTaskPicker.java @@ -36,7 +36,7 @@ public class PriorityTaskPicker /** * Creates an executor with a specific priority. - * Higher priority executors have more entries in the distribution queue, giving them a greater chance to run tasks. + * Higher priority executors have more exponentially entries in the distribution queue, giving them a greater chance to run tasks. * * @param priority the priority level of the executor * @return a newly created Executor @@ -45,7 +45,7 @@ public class PriorityTaskPicker { Executor executor = new Executor(); - int entriesToAdd = priority + 1; + int entriesToAdd = 1 << priority; int gapBetweenEntries = (int) (1 / (double) entriesToAdd * this.executorQueue.size()); // Distribute the executor's entries in the queue, ensuring fair distribution @@ -135,7 +135,19 @@ public class PriorityTaskPicker public void shutdown() { this.isShutDown = true; - this.threadPoolExecutor.shutdown(); + + try + { + this.threadPoolExecutor.shutdown(); + if (!this.threadPoolExecutor.awaitTermination(5, TimeUnit.SECONDS)) + { + this.threadPoolExecutor.shutdownNow(); + } + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java index 3d697f9aa..7434fbbe2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java @@ -91,15 +91,15 @@ public class ThreadPoolUtil taskPicker = new PriorityTaskPicker(); // IO should never be stuck waiting for something else to complete - networkCompressionThreadPool = taskPicker.createExecutor(3); - fileHandlerThreadPool = taskPicker.createExecutor(3); + networkCompressionThreadPool = taskPicker.createExecutor(4); + fileHandlerThreadPool = taskPicker.createExecutor(4); // Normal priority tasks - chunkToLodBuilderThreadPool = taskPicker.createExecutor(2); + chunkToLodBuilderThreadPool = taskPicker.createExecutor(3); updatePropagatorThreadPool = taskPicker.createExecutor(2); - // World gen tasks are heavy and nothing strictly depends on them, so it may wait a bit - worldGenThreadPool = taskPicker.createExecutor(1); + // World gen tasks are heavy and nothing strictly depends on them, so they may wait a bit + worldGenThreadPool = taskPicker.createExecutor(0);