diff --git a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java index 40616a27a..8db125649 100644 --- a/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java +++ b/src/main/java/com/seibel/lod/core/builders/bufferBuilding/LodBufferBuilderFactory.java @@ -96,9 +96,11 @@ public class LodBufferBuilderFactory private static final IMinecraftWrapper MC = SingletonHandler.get(IMinecraftWrapper.class); /** The thread used to generate new LODs off the main thread. */ - public static final ExecutorService mainGenThread = Executors.newSingleThreadExecutor(new LodThreadFactory(LodBufferBuilderFactory.class.getSimpleName() + " - main")); + public static final ExecutorService mainGenThread = Executors.newSingleThreadExecutor( + new LodThreadFactory(LodBufferBuilderFactory.class.getSimpleName() + " - main", Thread.NORM_PRIORITY-2)); /** The threads used to generate buffers. */ - public static final ExecutorService bufferBuilderThreads = Executors.newFixedThreadPool(CONFIG.client().advanced().threading().getNumberOfBufferBuilderThreads(), new ThreadFactoryBuilder().setNameFormat("Buffer-Builder-%d").build()); + public static final ExecutorService bufferBuilderThreads = Executors.newFixedThreadPool(CONFIG.client().advanced().threading().getNumberOfBufferBuilderThreads(), + new LodThreadFactory("BufferBuilder", Thread.NORM_PRIORITY-2)); public static final long MAX_BUFFER_UPLOAD_TIMEOUT_NANOSECONDS = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); diff --git a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java index 802b5d4f1..f434b9f16 100644 --- a/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java +++ b/src/main/java/com/seibel/lod/core/builders/lodBuilding/LodBuilder.java @@ -66,7 +66,8 @@ public class LodBuilder //public static final ExecutorService lodGenThreadPool = Executors.newFixedThreadPool(8, new ThreadFactoryBuilder().setNameFormat("Lod-Builder-%d").build()); - private final ExecutorService lodGenThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName())); + private final ExecutorService lodGenThreadPool = Executors.newSingleThreadExecutor( + new LodThreadFactory(this.getClass().getSimpleName(), Thread.NORM_PRIORITY-1)); private final ILodConfigWrapperSingleton config = SingletonHandler.get(ILodConfigWrapperSingleton.class); diff --git a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java index 729a34fea..ca24dab51 100644 --- a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java +++ b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java @@ -61,9 +61,10 @@ public class LodWorldGenerator /** This holds the thread used to create LOD generation requests off the main thread. */ - private final ExecutorService mainGenThread = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName() + " world generator")); + private final ExecutorService mainGenThread = Executors.newSingleThreadExecutor( + new LodThreadFactory(this.getClass().getSimpleName() + " world generator", 1)); private ExecutorService genSubThreads = Executors.newFixedThreadPool(CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(), - new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); + new LodThreadFactory("Gen-Worker-Thread", 1)); /** we only want to queue up one generator thread at a time */ diff --git a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java index f0c9b8690..f4d091514 100644 --- a/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/core/handlers/LodDimensionFileHandler.java @@ -92,7 +92,8 @@ public class LodDimensionFileHandler * at a time */ private final AtomicBoolean isFileWritingThreadRunning = new AtomicBoolean(false); - private ExecutorService fileWritingThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName())); + private ExecutorService fileWritingThreadPool = Executors.newSingleThreadExecutor( + new LodThreadFactory(this.getClass().getSimpleName(), Thread.NORM_PRIORITY+1)); private final ConcurrentHashMap regionToSave = new ConcurrentHashMap(); @@ -345,7 +346,7 @@ public class LodDimensionFileHandler ClientApi.LOGGER.error("File writing wait is interrupted! File data may not be saved correctly and may cause corruptions!!!"); e.printStackTrace(); } finally { - fileWritingThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName())); + fileWritingThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName(), Thread.NORM_PRIORITY+1)); } } } diff --git a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java index b3bdf96d2..b773acca4 100644 --- a/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java +++ b/src/main/java/com/seibel/lod/core/objects/lod/LodDimension.java @@ -97,7 +97,8 @@ public class LodDimension private boolean isCutting = false; private boolean isExpanding = false; - private final ExecutorService cutAndExpandThread = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName() + " - Cut and Expand")); + private final ExecutorService cutAndExpandThread = Executors.newSingleThreadExecutor( + new LodThreadFactory(this.getClass().getSimpleName() + " - Cut and Expand", Thread.NORM_PRIORITY-1)); /** diff --git a/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java b/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java index c12e8e0ff..e9791c349 100644 --- a/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java +++ b/src/main/java/com/seibel/lod/core/util/LodThreadFactory.java @@ -30,17 +30,23 @@ import java.util.concurrent.ThreadFactory; public class LodThreadFactory implements ThreadFactory { public final String threadName; + public final int priority; + private int threadCount = 0; - public LodThreadFactory(String newThreadName) + public LodThreadFactory(String newThreadName, int priority) { + if (priority < 1 || priority > 10) throw new IllegalArgumentException("Thread priority should be [1-10]!"); threadName = newThreadName + " Thread"; + this.priority = priority; } @Override public Thread newThread(Runnable r) { - return new Thread(r, threadName); + Thread t = new Thread(r, threadName + "[" + (threadCount++) + "]"); + t.setPriority(priority); + return t; } }