diff --git a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java index 6f6deca0..29c2cb6a 100644 --- a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java @@ -46,15 +46,19 @@ public class ServiceThreadPool { //Set worker affinity if possible CpuLayout.setThreadAffinity(CpuLayout.CORES[2 + (threadId % (CpuLayout.CORES.length - 2))]); } - - ThreadUtils.SetSelfThreadPriorityWin32(ThreadUtils.WIN32_THREAD_PRIORITY_LOWEST); - //ThreadUtils.SetSelfThreadPriorityWin32(ThreadUtils.WIN32_THREAD_MODE_BACKGROUND_BEGIN); - + if (threadId != 0) { + ThreadUtils.SetSelfThreadPriorityWin32(ThreadUtils.WIN32_THREAD_PRIORITY_LOWEST); + //ThreadUtils.SetSelfThreadPriorityWin32(ThreadUtils.WIN32_THREAD_MODE_BACKGROUND_BEGIN); + } this.worker(threadId); }); worker.setDaemon(false); worker.setName("Service worker #" + i); - worker.setPriority(priority); + if (i == 0) {//Give the first thread normal priority, this helps if the system is under huge load for voxy to get some work done + worker.setPriority(Thread.NORM_PRIORITY); + } else { + worker.setPriority(priority); + } worker.start(); worker.setUncaughtExceptionHandler(this::handleUncaughtException); this.workers[i] = worker; diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index 12e2ec15..e78d48d4 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -86,6 +86,9 @@ public class VoxelIngestService { } public void enqueueIngest(WorldEngine engine, WorldChunk chunk) { + if (!this.threads.isAlive()) { + return; + } if (!engine.isLive()) { throw new IllegalStateException("Tried inserting chunk into WorldEngine that was not alive"); } @@ -117,7 +120,12 @@ public class VoxelIngestService { } this.ingestQueue.add(new IngestSection(chunk.getPos().x, i, chunk.getPos().z, engine, section, bl, sl)); - this.threads.execute(); + try { + this.threads.execute(); + } catch (Exception e) { + Logger.error("Executing had an error: assume shutting down, aborting",e); + break; + } } }