From 7bbfcc0b7e1a5bcdba11f3c18d3b6e164e029d1e Mon Sep 17 00:00:00 2001 From: jeepingben Date: Fri, 5 Sep 2014 08:34:34 -0400 Subject: [PATCH 1/2] Create LIFOBlockingDeque.java Add support for LIFO blocking queue (deque actually) --- .../src/net/osmand/util/LIFOBlockingDeque.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 OsmAnd-java/src/net/osmand/util/LIFOBlockingDeque.java diff --git a/OsmAnd-java/src/net/osmand/util/LIFOBlockingDeque.java b/OsmAnd-java/src/net/osmand/util/LIFOBlockingDeque.java new file mode 100644 index 0000000000..41f055e0d3 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/util/LIFOBlockingDeque.java @@ -0,0 +1,18 @@ +package net.osmand.util; + +import java.util.concurrent.LinkedBlockingDeque; + +public class LIFOBlockingDeque extends LinkedBlockingDeque { + + private static final long serialVersionUID = 1L; + + @Override + public boolean offer(T t) { + return super.offerFirst(t); + } + + @Override + public T remove() { + return super.removeFirst(); + } +} From d656aa54e6ce3bf715b7b69da0aec790d65a3482 Mon Sep 17 00:00:00 2001 From: jeepingben Date: Fri, 5 Sep 2014 08:39:15 -0400 Subject: [PATCH 2/2] Switch MapTileDownloader order to LIFO -Issue 2364 Fetch the area the user visited most recently first. This makes the GUI feel more responsive. --- OsmAnd-java/src/net/osmand/map/MapTileDownloader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java index bdef27066b..07bcd3715d 100644 --- a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java +++ b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java @@ -12,12 +12,12 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import net.osmand.PlatformUtil; import net.osmand.util.Algorithms; +import net.osmand.util.LIFOBlockingDeque; import org.apache.commons.logging.Log; @@ -106,7 +106,7 @@ public class MapTileDownloader { public MapTileDownloader(int numberOfThreads){ threadPoolExecutor = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, TILE_DOWNLOAD_SECONDS_TO_WORK, - TimeUnit.SECONDS, new LinkedBlockingQueue()); + TimeUnit.SECONDS, new LIFOBlockingDeque()); // 1.6 method but very useful to kill non-running threads // threadPoolExecutor.allowCoreThreadTimeOut(true); currentlyDownloaded = Collections.synchronizedSet(new HashSet());