From 03b280fe2def91f9c147f0f51853d23ec5993d25 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Thu, 15 Dec 2011 00:33:40 +0800 Subject: [PATCH] Add 'usenormalthreadpriority' setting (makes renders on Windows use normal priority) --- src/main/java/org/dynmap/AsynchronousQueue.java | 7 +++++-- src/main/java/org/dynmap/MapManager.java | 10 ++++++++-- src/main/resources/configuration.txt | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dynmap/AsynchronousQueue.java b/src/main/java/org/dynmap/AsynchronousQueue.java index 6e47aae1..e2d31c4d 100644 --- a/src/main/java/org/dynmap/AsynchronousQueue.java +++ b/src/main/java/org/dynmap/AsynchronousQueue.java @@ -17,14 +17,16 @@ public class AsynchronousQueue { private int accelDequeueThresh; private int pendingcnt; private int pendinglimit; + private boolean normalprio; - public AsynchronousQueue(Handler handler, int dequeueTime, int accelDequeueThresh, int accelDequeueTime, int pendinglimit) { + public AsynchronousQueue(Handler handler, int dequeueTime, int accelDequeueThresh, int accelDequeueTime, int pendinglimit, boolean normalprio) { this.handler = handler; this.dequeueTime = dequeueTime; this.accelDequeueTime = accelDequeueTime; this.accelDequeueThresh = accelDequeueThresh; if(pendinglimit < 1) pendinglimit = 1; this.pendinglimit = pendinglimit; + this.normalprio = normalprio; } public boolean push(T t) { @@ -83,7 +85,8 @@ public class AsynchronousQueue { }); thread.start(); try { - thread.setPriority(Thread.MIN_PRIORITY); + if(!normalprio) + thread.setPriority(Thread.MIN_PRIORITY); } catch (SecurityException e) { Log.info("Failed to set minimum priority for worker thread!"); } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 1995f9a7..5acd0009 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -50,6 +50,7 @@ public class MapManager { private int progressinterval = 100; private boolean saverestorepending = true; private boolean hideores = false; + private boolean usenormalpriority = false; private boolean pauseupdaterenders = false; private boolean pausefullrenders = false; @@ -117,7 +118,8 @@ public class MapManager { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); - t.setPriority(Thread.MIN_PRIORITY); + if(!mapman.usenormalpriority) + t.setPriority(Thread.MIN_PRIORITY); t.setName("Dynmap Render Thread"); return t; } @@ -658,6 +660,9 @@ public class MapManager { /* Get block hiding data, if any */ hideores = configuration.getBoolean("hideores", false); + /* See what priority to use */ + usenormalpriority = configuration.getBoolean("usenormalthreadpriority", false); + /* Clear color scheme */ ColorScheme.reset(); @@ -684,7 +689,8 @@ public class MapManager { (int) (configuration.getDouble("renderinterval", 0.5) * 1000), configuration.getInteger("renderacceleratethreshold", 30), (int)(configuration.getDouble("renderaccelerateinterval", 0.2) * 1000), - configuration.getInteger("tiles-rendered-at-once", (Runtime.getRuntime().availableProcessors()+1)/2)); + configuration.getInteger("tiles-rendered-at-once", (Runtime.getRuntime().availableProcessors()+1)/2), + usenormalpriority); /* On dedicated thread, so default to no delays */ timeslice_int = (long)(configuration.getDouble("timesliceinterval", 0.0) * 1000); diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index 4e7cbd4e..87397b2c 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -133,6 +133,11 @@ renderaccelerateinterval: 0.2 # How many update tiles to work on at once (if not defined, default is 1/2 the number of cores) tiles-rendered-at-once: 2 +# If true, use normal priority threads for rendering (versus low priority) - this can keep rendering +# from starving on busy Windows boxes (Linux JVMs pretty much ignore thread priority), but may result +# in more competition for CPU resources with other processes +usenormalthreadpriority: true + # Save and restore pending tile renders - prevents their loss on server shutdown or /reload saverestorepending: true