Changeset 17654 in josm for trunk


Ignore:
Timestamp:
2021-03-24T08:16:29+01:00 (4 years ago)
Author:
GerdP
Message:

fix #20416: Download (incomplete) members: Cancel does not work and timeouts while download relation with members works

  • let the Cancel button do a shutdownNow() on the executor so that user doesn't have to wait (I hope)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r17635 r17654  
    8181    private boolean recurseDownAppended = true;
    8282
     83    private ExecutorService exec;
     84
    8385    /**
    8486     * Constructs a {@code MultiFetchServerObjectReader}.
     
    320322        int threadsNumber = Config.getPref().getInt("osm.download.threads", OsmApi.MAX_DOWNLOAD_THREADS);
    321323        threadsNumber = Utils.clamp(threadsNumber, 1, OsmApi.MAX_DOWNLOAD_THREADS);
    322         final ExecutorService exec = Executors.newFixedThreadPool(
     324        exec = Executors.newFixedThreadPool(
    323325                threadsNumber, Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY));
    324326        CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec);
    325327        List<Future<FetchResult>> jobs = new ArrayList<>();
    326         while (!toFetch.isEmpty()) {
     328        while (!toFetch.isEmpty() && !isCanceled()) {
    327329            jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor)));
    328330        }
     
    358360            }
    359361        }
     362        exec = null;
    360363    }
    361364
     
    706709        }
    707710    }
     711
     712    @Override
     713    public void cancel() {
     714        super.cancel();
     715        if (exec != null)
     716            exec.shutdownNow();
     717    }
    708718}
Note: See TracChangeset for help on using the changeset viewer.