Changeset 31472 in osm
- Timestamp:
- 2015-08-10T12:41:58+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31460 r31472 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.ArrayList; 5 6 import java.util.concurrent.ArrayBlockingQueue; 6 7 import java.util.concurrent.ConcurrentHashMap; … … 36 37 public static final int MANUAL = 2; 37 38 39 /** All the Threads that have been run. Used to interrupt them properly. */ 40 private static ArrayList<Thread> threads = new ArrayList<>(); 41 38 42 /** Max area to be downloaded */ 39 43 public static final double MAX_AREA = Main.pref.getDouble( … … 45 49 public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"; 46 50 /** Executor that will run the petitions. */ 47 private static ThreadPoolExecutor EXECUTOR; 51 private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5, 52 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50)); 48 53 49 54 /** … … 62 67 queryStringParts.put("max_lat", maxLatLon.lat()); 63 68 queryStringParts.put("max_lon", maxLatLon.lon()); 64 EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,65 new ArrayBlockingQueue<Runnable>(50));66 69 run(new MapillarySquareDownloadManagerThread(queryStringParts)); 67 70 } 68 71 69 72 private static void run(Thread t) { 73 threads.add(t); 70 74 EXECUTOR.execute(t); 71 75 } … … 215 219 */ 216 220 public static void stopAll() { 221 for (Thread t : threads) { 222 if (t.isAlive()) 223 System.out.println(t); 224 t.interrupt(); 225 } 226 threads.clear(); 217 227 EXECUTOR.shutdownNow(); 228 try { 229 EXECUTOR.awaitTermination(30, TimeUnit.SECONDS); 230 } catch (InterruptedException e) { 231 // TODO Auto-generated catch block 232 e.printStackTrace(); 233 } 218 234 EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, 219 235 new ArrayBlockingQueue<Runnable>(50)); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31456 r31472 30 30 private final String sequenceQueryString; 31 31 private final String signQueryString; 32 33 private ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(3, 5, 34 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 35 private ThreadPoolExecutor completeExecutor = new ThreadPoolExecutor(3, 5, 36 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 37 private ThreadPoolExecutor signsExecutor = new ThreadPoolExecutor(3, 5, 25, 38 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 32 39 33 40 /** … … 78 85 } finally { 79 86 PluginState.finishDownload(); 80 MapillaryUtils.updateHelpText();81 87 } 82 88 MapillaryUtils.updateHelpText(); … … 87 93 88 94 private void downloadSequences() throws InterruptedException { 89 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,90 new ArrayBlockingQueue<Runnable>(5));91 95 int page = 0; 92 while (!ex.isShutdown()) { 93 ex.execute(new MapillarySequenceDownloadThread(ex, 94 this.sequenceQueryString + "&page=" + page + "&limit=10")); 95 while (ex.getQueue().remainingCapacity() == 0) 96 while (!this.downloadExecutor.isShutdown()) { 97 this.downloadExecutor.execute(new MapillarySequenceDownloadThread( 98 this.downloadExecutor, this.sequenceQueryString + "&page=" + page 99 + "&limit=10")); 100 while (this.downloadExecutor.getQueue().remainingCapacity() == 0) 96 101 Thread.sleep(500); 97 102 page++; 98 103 } 99 ex.awaitTermination(15, TimeUnit.SECONDS);104 this.downloadExecutor.awaitTermination(15, TimeUnit.SECONDS); 100 105 MapillaryData.dataUpdated(); 101 106 } 102 107 103 108 private void completeImages() throws InterruptedException { 104 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,105 new ArrayBlockingQueue<Runnable>(5));106 109 int page = 0; 107 while (!ex.isShutdown()) { 108 ex.execute(new MapillaryImageInfoDownloaderThread(ex, 109 this.imageQueryString + "&page=" + page + "&limit=20")); 110 while (ex.getQueue().remainingCapacity() == 0) 110 while (!this.completeExecutor.isShutdown()) { 111 this.completeExecutor.execute(new MapillaryImageInfoDownloaderThread( 112 this.completeExecutor, this.imageQueryString + "&page=" + page 113 + "&limit=20")); 114 while (this.completeExecutor.getQueue().remainingCapacity() == 0) 111 115 Thread.sleep(100); 112 116 page++; 113 117 } 114 ex.awaitTermination(15, TimeUnit.SECONDS);118 this.completeExecutor.awaitTermination(15, TimeUnit.SECONDS); 115 119 } 116 120 117 121 private void downloadSigns() throws InterruptedException { 118 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,119 new ArrayBlockingQueue<Runnable>(5));120 122 int page = 0; 121 while (!ex.isShutdown()) { 122 ex.execute(new MapillaryTrafficSignDownloaderThread(ex, 123 this.signQueryString + "&page=" + page + "&limit=20")); 124 while (ex.getQueue().remainingCapacity() == 0) 123 while (!this.signsExecutor.isShutdown()) { 124 this.signsExecutor.execute(new MapillaryTrafficSignDownloaderThread( 125 this.signsExecutor, this.signQueryString + "&page=" + page 126 + "&limit=20")); 127 while (this.signsExecutor.getQueue().remainingCapacity() == 0) 125 128 Thread.sleep(100); 126 129 page++; 127 130 } 128 ex.awaitTermination(15, TimeUnit.SECONDS); 131 this.signsExecutor.awaitTermination(15, TimeUnit.SECONDS); 132 } 133 134 @Override 135 public void interrupt() { 136 super.interrupt(); 137 this.downloadExecutor.shutdownNow(); 138 this.completeExecutor.shutdownNow(); 139 this.signsExecutor.shutdownNow(); 140 try { 141 this.downloadExecutor.awaitTermination(15, TimeUnit.SECONDS); 142 this.completeExecutor.awaitTermination(15, TimeUnit.SECONDS); 143 this.signsExecutor.awaitTermination(15, TimeUnit.SECONDS); 144 } catch (InterruptedException e) { 145 Main.error(e); 146 } 129 147 } 130 148 }
Note:
See TracChangeset
for help on using the changeset viewer.