Merge pull request #867 from jeepingben/master

Use LIFO order for downloading map tiles (issue 2364)
This commit is contained in:
vshcherb 2014-09-05 17:18:50 +02:00
commit cc666dcb9a
2 changed files with 20 additions and 2 deletions

View file

@ -12,12 +12,12 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.LIFOBlockingDeque;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -106,7 +106,7 @@ public class MapTileDownloader {
public MapTileDownloader(int numberOfThreads){ public MapTileDownloader(int numberOfThreads){
threadPoolExecutor = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, TILE_DOWNLOAD_SECONDS_TO_WORK, threadPoolExecutor = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, TILE_DOWNLOAD_SECONDS_TO_WORK,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>());
// 1.6 method but very useful to kill non-running threads // 1.6 method but very useful to kill non-running threads
// threadPoolExecutor.allowCoreThreadTimeOut(true); // threadPoolExecutor.allowCoreThreadTimeOut(true);
currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>()); currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>());

View file

@ -0,0 +1,18 @@
package net.osmand.util;
import java.util.concurrent.LinkedBlockingDeque;
public class LIFOBlockingDeque<T> extends LinkedBlockingDeque<T> {
private static final long serialVersionUID = 1L;
@Override
public boolean offer(T t) {
return super.offerFirst(t);
}
@Override
public T remove() {
return super.removeFirst();
}
}