Changeset 18821 in josm for trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
- Timestamp:
- 2023-08-24T17:23:11+02:00 (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r18129 r18821 48 48 * Retrieves a set of {@link OsmPrimitive}s from an OSM server using the so called 49 49 * Multi Fetch API. 50 * 50 * <p> 51 51 * Usage: 52 52 * <pre> … … 128 128 * Remembers an {@link OsmPrimitive}'s id. The id will 129 129 * later be fetched as part of a Multi Get request. 130 * 130 * <p> 131 131 * Ignore the id if it represents a new primitives. 132 132 * … … 326 326 CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec); 327 327 List<Future<FetchResult>> jobs = new ArrayList<>(); 328 while (!toFetch.isEmpty() && !isCanceled()) { 329 jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor))); 328 // There exists a race condition where this is cancelled after isCanceled is called, such that 329 // the exec ThreadPool has been shut down. This can cause a RejectedExecutionException. 330 synchronized (this) { 331 while (!toFetch.isEmpty() && !isCanceled()) { 332 jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor))); 333 } 330 334 } 331 335 // Run the fetchers … … 348 352 } 349 353 } catch (InterruptedException | ExecutionException e) { 354 if (e instanceof InterruptedException) { 355 Thread.currentThread().interrupt(); 356 } 350 357 Logging.error(e); 351 358 if (e.getCause() instanceof OsmTransferException) … … 369 376 * the latest version of the primitive (if any), even if the primitive is not visible (i.e. if 370 377 * visible==false). 371 * 378 * <p> 372 379 * Invoke {@link #getMissingPrimitives()} to get a list of primitives which have not been 373 380 * found on the server (the server response code was 404) … … 589 596 } 590 597 if (pkg.size() == 1) { 591 FetchResult res = new FetchResult(new DataSet(), new HashSet< PrimitiveId>());598 FetchResult res = new FetchResult(new DataSet(), new HashSet<>()); 592 599 res.missingPrimitives.add(new SimplePrimitiveId(pkg.iterator().next(), type)); 593 600 return res; … … 668 675 * invokes a sequence of Multi Gets for individual ids in a set of ids and a given {@link OsmPrimitiveType}. 669 676 * The retrieved primitives are merged to {@link #outputDataSet}. 670 * 677 * <p> 671 678 * This method is used if one of the ids in pkg doesn't exist (the server replies with return code 404). 672 679 * If the set is fetched with this method it is possible to find out which of the ids doesn't exist. … … 682 689 protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) 683 690 throws OsmTransferException { 684 FetchResult result = new FetchResult(new DataSet(), new HashSet< PrimitiveId>());691 FetchResult result = new FetchResult(new DataSet(), new HashSet<>()); 685 692 String baseUrl = OsmApi.getOsmApi().getBaseUrl(); 686 693 for (long id : pkg) { … … 713 720 public void cancel() { 714 721 super.cancel(); 715 if (exec != null) 716 exec.shutdownNow(); 722 // Synchronized to avoid a RejectedExecutionException in fetchPrimitives 723 // We don't want to synchronize on the super.cancel() call. 724 synchronized (this) { 725 if (exec != null) { 726 exec.shutdownNow(); 727 } 728 } 717 729 } 718 730 }
Note:
See TracChangeset
for help on using the changeset viewer.