From 8403fbf0623a852396f17ebce42ec73239f61345 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 16 Sep 2020 12:29:38 +0300 Subject: [PATCH] executor pla a route bug fix --- .../main/java/net/osmand/router/RoutePlannerFrontEnd.java | 5 ++++- OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index 5aefb2ac44..663c9ea384 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -243,6 +243,9 @@ public class RoutePlannerFrontEnd { start = gpxPoints.get(0); } while (start != null && !gctx.ctx.calculationProgress.isCancelled) { + if (Thread.currentThread().isInterrupted()) { + return null; + } double routeDist = gctx.MAXIMUM_STEP_APPROXIMATION; GpxPoint next = findNextGpxPointWithin(gctx, gpxPoints, start, routeDist); boolean routeFound = false; @@ -256,7 +259,7 @@ public class RoutePlannerFrontEnd { if (routeFound) { // route is found - cut the end of the route and move to next iteration // start.stepBackRoute = new ArrayList(); -// boolean stepBack = true; +// boolean stepBack = true; boolean stepBack = stepBackAndFindPrevPointInRoute(gctx, gpxPoints, start, next); if (!stepBack) { // not supported case (workaround increase MAXIMUM_STEP_APPROXIMATION) diff --git a/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java b/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java index 7e6b089620..61d8408fe6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java +++ b/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -44,6 +45,7 @@ public class GpxApproximator { private ThreadPoolExecutor singleThreadedExecutor; private GpxApproximationProgressCallback approximationProgress; + private Future currentApproximationTask; public interface GpxApproximationProgressCallback { @@ -152,7 +154,10 @@ public class GpxApproximator { this.gctx = gctx; startProgress(); updateProgress(gctx); - singleThreadedExecutor.submit(new Runnable() { + if (currentApproximationTask != null) { + currentApproximationTask.cancel(true); + } + currentApproximationTask = singleThreadedExecutor.submit(new Runnable() { @Override public void run() { try {