Tighten up update queue concurrency limits - don't stomp fullrender/radiusrender

This commit is contained in:
Mike Primm 2011-10-07 18:19:38 -05:00
parent e67bfad65a
commit a2df443aeb
2 changed files with 18 additions and 18 deletions

View File

@ -2,15 +2,14 @@ package org.dynmap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
public class AsynchronousQueue<T> { public class AsynchronousQueue<T> {
private Object lock = new Object(); private Object lock = new Object();
private Thread thread; private Thread thread;
private LinkedList<T> queue = new LinkedList<T>(); private LinkedBlockingQueue<T> queue = new LinkedBlockingQueue<T>();
private Set<T> set = new HashSet<T>(); private Set<T> set = new HashSet<T>();
private Handler<T> handler; private Handler<T> handler;
private int dequeueTime; private int dequeueTime;
@ -29,21 +28,20 @@ public class AsynchronousQueue<T> {
public boolean push(T t) { public boolean push(T t) {
synchronized (lock) { synchronized (lock) {
if (set.add(t)) { if (!set.add(t)) {
queue.addLast(t);
return true;
}
return false; return false;
} }
} }
queue.offer(t);
private T pop() { return true;
synchronized (lock) {
T t = queue.pollFirst();
if(t != null)
set.remove(t);
return t;
} }
private T pop() throws InterruptedException {
T t = queue.take();
synchronized (lock) {
set.remove(t);
}
return t;
} }
public boolean remove(T t) { public boolean remove(T t) {
@ -124,7 +122,6 @@ public class AsynchronousQueue<T> {
synchronized(lock) { synchronized(lock) {
pendingcnt++; pendingcnt++;
} }
Log.info("handle(" + t + ")");
handler.handle(t); handler.handle(t);
} }
if(set.size() >= accelDequeueThresh) if(set.size() >= accelDequeueThresh)
@ -148,7 +145,6 @@ public class AsynchronousQueue<T> {
} }
public void done(T t) { public void done(T t) {
Log.info("done(" + t + ")");
synchronized (lock) { synchronized (lock) {
if(pendingcnt > 0) pendingcnt--; if(pendingcnt > 0) pendingcnt--;
lock.notifyAll(); lock.notifyAll();

View File

@ -207,7 +207,6 @@ public class MapManager {
FullWorldRenderState(MapTile t) { FullWorldRenderState(MapTile t) {
world = getWorld(t.getWorld().getName()); world = getWorld(t.getWorld().getName());
tile0 = t; tile0 = t;
Log.info("job(" + t + ")");
cxmin = czmin = Integer.MIN_VALUE; cxmin = czmin = Integer.MIN_VALUE;
cxmax = czmax = Integer.MAX_VALUE; cxmax = czmax = Integer.MAX_VALUE;
} }
@ -627,7 +626,9 @@ public class MapManager {
new Handler<MapTile>() { new Handler<MapTile>() {
@Override @Override
public void handle(MapTile t) { 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), (int) (configuration.getDouble("renderinterval", 0.5) * 1000),
@ -937,18 +938,21 @@ public class MapManager {
Debug.debug("Invalidating tile " + tile.getFilename()); 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((mapman != null) && (mapman.render_pool != null)) {
if(delay_in_msec > 0) if(delay_in_msec > 0)
mapman.render_pool.schedule(job, delay_in_msec, TimeUnit.MILLISECONDS); mapman.render_pool.schedule(job, delay_in_msec, TimeUnit.MILLISECONDS);
else else
mapman.render_pool.execute(job); mapman.render_pool.execute(job);
return true;
} }
else
return false;
} }
public void startRendering() { public void startRendering() {
tileQueue.start();
render_pool = new DynmapScheduledThreadPoolExecutor(); render_pool = new DynmapScheduledThreadPoolExecutor();
tileQueue.start();
scheduleDelayedJob(new DoZoomOutProcessing(), 60000); scheduleDelayedJob(new DoZoomOutProcessing(), 60000);
scheduleDelayedJob(new CheckWorldTimes(), 5000); scheduleDelayedJob(new CheckWorldTimes(), 5000);
/* Resume pending jobs */ /* Resume pending jobs */