From a2df443aeb3a950abb656e4ce600ba117d2544c8 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 7 Oct 2011 18:19:38 -0500 Subject: [PATCH] Tighten up update queue concurrency limits - don't stomp fullrender/radiusrender --- .../java/org/dynmap/AsynchronousQueue.java | 24 ++++++++----------- src/main/java/org/dynmap/MapManager.java | 12 ++++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/dynmap/AsynchronousQueue.java b/src/main/java/org/dynmap/AsynchronousQueue.java index c84207ad..6d3637e2 100644 --- a/src/main/java/org/dynmap/AsynchronousQueue.java +++ b/src/main/java/org/dynmap/AsynchronousQueue.java @@ -2,15 +2,14 @@ package org.dynmap; import java.util.ArrayList; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; -import java.util.NoSuchElementException; import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; public class AsynchronousQueue { private Object lock = new Object(); private Thread thread; - private LinkedList queue = new LinkedList(); + private LinkedBlockingQueue queue = new LinkedBlockingQueue(); private Set set = new HashSet(); private Handler handler; private int dequeueTime; @@ -29,21 +28,20 @@ public class AsynchronousQueue { public boolean push(T t) { synchronized (lock) { - if (set.add(t)) { - queue.addLast(t); - return true; + if (!set.add(t)) { + return false; } - return false; } + queue.offer(t); + return true; } - private T pop() { + private T pop() throws InterruptedException { + T t = queue.take(); synchronized (lock) { - T t = queue.pollFirst(); - if(t != null) - set.remove(t); - return t; + set.remove(t); } + return t; } public boolean remove(T t) { @@ -124,7 +122,6 @@ public class AsynchronousQueue { synchronized(lock) { pendingcnt++; } - Log.info("handle(" + t + ")"); handler.handle(t); } if(set.size() >= accelDequeueThresh) @@ -148,7 +145,6 @@ public class AsynchronousQueue { } public void done(T t) { - Log.info("done(" + t + ")"); synchronized (lock) { if(pendingcnt > 0) pendingcnt--; lock.notifyAll(); diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 319fcb8d..6a572f1e 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -207,7 +207,6 @@ public class MapManager { FullWorldRenderState(MapTile t) { world = getWorld(t.getWorld().getName()); tile0 = t; - Log.info("job(" + t + ")"); cxmin = czmin = Integer.MIN_VALUE; cxmax = czmax = Integer.MAX_VALUE; } @@ -627,7 +626,9 @@ public class MapManager { new Handler() { @Override public void handle(MapTile t) { - scheduleDelayedJob(new FullWorldRenderState(t), 0); + FullWorldRenderState job = new FullWorldRenderState(t); + if(!scheduleDelayedJob(job, 0)) + job.cleanup(); } }, (int) (configuration.getDouble("renderinterval", 0.5) * 1000), @@ -937,18 +938,21 @@ public class MapManager { Debug.debug("Invalidating tile " + tile.getFilename()); } - public static void scheduleDelayedJob(Runnable job, long delay_in_msec) { + public static boolean scheduleDelayedJob(Runnable job, long delay_in_msec) { if((mapman != null) && (mapman.render_pool != null)) { if(delay_in_msec > 0) mapman.render_pool.schedule(job, delay_in_msec, TimeUnit.MILLISECONDS); else mapman.render_pool.execute(job); + return true; } + else + return false; } public void startRendering() { - tileQueue.start(); render_pool = new DynmapScheduledThreadPoolExecutor(); + tileQueue.start(); scheduleDelayedJob(new DoZoomOutProcessing(), 60000); scheduleDelayedJob(new CheckWorldTimes(), 5000); /* Resume pending jobs */