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.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<T> {
private Object lock = new Object();
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 Handler<T> handler;
private int dequeueTime;
@ -29,21 +28,20 @@ public class AsynchronousQueue<T> {
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<T> {
synchronized(lock) {
pendingcnt++;
}
Log.info("handle(" + t + ")");
handler.handle(t);
}
if(set.size() >= accelDequeueThresh)
@ -148,7 +145,6 @@ public class AsynchronousQueue<T> {
}
public void done(T t) {
Log.info("done(" + t + ")");
synchronized (lock) {
if(pendingcnt > 0) pendingcnt--;
lock.notifyAll();

View File

@ -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<MapTile>() {
@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 */