Changeset 8734 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-09-08T15:20:34+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r8513 r8734 168 168 * and sequential. 169 169 */ 170 public static final ExecutorService worker = new ProgressMonitorExecutor( );170 public static final ExecutorService worker = new ProgressMonitorExecutor("main-worker-%d", Thread.NORM_PRIORITY); 171 171 172 172 /** … … 625 625 626 626 try { 627 for (Future<Void> i : Executors.newFixedThreadPool( 628 Runtime.getRuntime().availableProcessors()).invokeAll(tasks)) { 627 final ExecutorService service = Executors.newFixedThreadPool( 628 Runtime.getRuntime().availableProcessors(), Utils.newThreadFactory("main-init-%d", Thread.NORM_PRIORITY)); 629 for (Future<Void> i : service.invokeAll(tasks)) { 629 630 i.get(); 630 631 } -
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r8673 r8734 77 77 // make queue of LIFO type - so recently requested tiles will be loaded first (assuming that these are which user is waiting to see) 78 78 new LinkedBlockingDeque<Runnable>(), 79 Utils. getNamedThreadFactory("JCS downloader")79 Utils.newThreadFactory("JCS-downloader-%d", Thread.NORM_PRIORITY) 80 80 ); 81 81 -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java
r8624 r8734 50 50 * and for TMS imagery 51 51 */ 52 private static ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER = getNewThreadPoolExecutor("TMS downloader");52 private static ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER = getNewThreadPoolExecutor("TMS-downloader-%d"); 53 53 54 54 … … 74 74 75 75 /** 76 * @param name name of the threads76 * @param nameFormat see {@link Utils#newThreadFactory(String, int)} 77 77 * @param workers number of worker thread to keep 78 78 * @return new ThreadPoolExecutor that will use a @see HostLimitQueue based queue 79 79 */ 80 public static ThreadPoolExecutor getNewThreadPoolExecutor(String name , int workers) {80 public static ThreadPoolExecutor getNewThreadPoolExecutor(String nameFormat, int workers) { 81 81 return new ThreadPoolExecutor( 82 82 workers, // keep the thread number constant … … 85 85 TimeUnit.SECONDS, 86 86 new HostLimitQueue(HOST_LIMIT.get().intValue()), 87 Utils. getNamedThreadFactory(name)87 Utils.newThreadFactory(nameFormat, Thread.NORM_PRIORITY) 88 88 ); 89 89 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMSCachedTileLoader.java
r8624 r8734 34 34 35 35 super(listener, cache, connectTimeout, readTimeout, headers); 36 setDownloadExecutor(TMSCachedTileLoader.getNewThreadPoolExecutor("WMS downloader", THREAD_LIMIT.get()));36 setDownloadExecutor(TMSCachedTileLoader.getNewThreadPoolExecutor("WMS-downloader-%d", THREAD_LIMIT.get())); 37 37 } 38 38 -
trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java
r8510 r8734 32 32 33 33 private static final Pair<Integer, ExecutorService> THREAD_POOL = 34 Utils.newThreadPool("multipolygon_creation.numberOfThreads" );34 Utils.newThreadPool("multipolygon_creation.numberOfThreads", "multipolygon-builder-%d", Thread.NORM_PRIORITY); 35 35 36 36 /** -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r8632 r8734 87 87 88 88 private static final Pair<Integer, ExecutorService> THREAD_POOL = 89 Utils.newThreadPool("mappaint.StyledMapRenderer.style_creation.numberOfThreads" );89 Utils.newThreadPool("mappaint.StyledMapRenderer.style_creation.numberOfThreads", "styled-map-renderer-%d", Thread.NORM_PRIORITY); 90 90 91 91 /** -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayerTask.java
r8510 r8734 17 17 * ExecutorService executorService = ... 18 18 * SaveLayerTask task = new SaveLayerTask(layer, monitor); 19 * Future<?> taskFuture = executorServ ce.submit(task)19 * Future<?> taskFuture = executorService.submit(task) 20 20 * try { 21 21 * // wait for the task to complete 22 22 * taskFuture.get(); 23 23 * } catch (Exception e) { 24 * e.printStackTrace k();24 * e.printStackTrace(); 25 25 * } 26 26 * </pre> -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r8510 r8734 51 51 import org.openstreetmap.josm.gui.util.GuiHelper; 52 52 import org.openstreetmap.josm.tools.ImageProvider; 53 import org.openstreetmap.josm.tools.Utils; 53 54 import org.openstreetmap.josm.tools.WindowGeometry; 54 55 … … 445 446 this.model = model; 446 447 this.monitor = monitor; 447 this.worker = Executors.newSingleThreadExecutor( );448 this.worker = Executors.newSingleThreadExecutor(Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY)); 448 449 } 449 450 -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r8510 r8734 31 31 * ExecutorService executorService = ... 32 32 * UploadLayerTask task = new UploadLayerTask(layer, monitor); 33 * Future<?> taskFuture = executorServ ce.submit(task)33 * Future<?> taskFuture = executorService.submit(task) 34 34 * try { 35 35 * // wait for the task to complete 36 36 * taskFuture.get(); 37 37 * } catch (Exception e) { 38 * e.printStackTrace k();38 * e.printStackTrace(); 39 39 * } 40 40 * </pre> -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r8660 r8734 37 37 import java.util.concurrent.ExecutorService; 38 38 import java.util.concurrent.Executors; 39 import java.util.concurrent.ThreadFactory;40 39 41 40 import javax.swing.Action; … … 95 94 96 95 boolean useThumbs = false; 97 private ExecutorService thumbsLoaderExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { 98 @Override 99 public Thread newThread(Runnable r) { 100 Thread t = new Thread(r); 101 t.setPriority(Thread.MIN_PRIORITY); 102 return t; 103 } 104 }); 96 private ExecutorService thumbsLoaderExecutor = 97 Executors.newSingleThreadExecutor(Utils.newThreadFactory("thumbnail-loader-%d", Thread.MIN_PRIORITY)); 105 98 private ThumbsLoader thumbsloader; 106 99 private boolean thumbsLoaderRunning = false; -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CacheContentsPanel.java
r8624 r8734 48 48 import org.openstreetmap.josm.tools.GBC; 49 49 import org.openstreetmap.josm.tools.Pair; 50 import org.openstreetmap.josm.tools.Utils; 50 51 51 52 /** … … 133 134 } 134 135 135 private final transient ExecutorService executor = Executors.newSingleThreadExecutor(); 136 private final transient ExecutorService executor = 137 Executors.newSingleThreadExecutor(Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY)); 136 138 137 139 /** -
trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitorExecutor.java
r7937 r8734 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.tools.Utils; 9 10 10 11 /** … … 16 17 public class ProgressMonitorExecutor extends ThreadPoolExecutor { 17 18 18 public ProgressMonitorExecutor() { 19 /** 20 * Creates a new {@code ProgressMonitorExecutor} 21 * @param nameFormat see {@link Utils#newThreadFactory(String, int)} 22 * @param threadPriority see {@link Utils#newThreadFactory(String, int)} 23 */ 24 public ProgressMonitorExecutor(final String nameFormat, final int threadPriority) { 19 25 super(1, 1, 0L, TimeUnit.MILLISECONDS, 20 new LinkedBlockingQueue<Runnable>()); 26 new LinkedBlockingQueue<Runnable>(), 27 Utils.newThreadFactory(nameFormat, threadPriority)); 21 28 } 22 29 -
trunk/src/org/openstreetmap/josm/io/MessageNotifier.java
r8510 r8734 30 30 import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent; 31 31 import org.openstreetmap.josm.tools.GBC; 32 import org.openstreetmap.josm.tools.Utils; 32 33 33 34 /** … … 46 47 public static final IntegerProperty PROP_INTERVAL = new IntegerProperty("message.notifier.interval", 5); 47 48 48 private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(); 49 private static final ScheduledExecutorService EXECUTOR = 50 Executors.newSingleThreadScheduledExecutor(Utils.newThreadFactory("message-notifier-%d", Thread.NORM_PRIORITY)); 49 51 50 52 private static final Runnable WORKER = new Worker(); -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r8540 r8734 38 38 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 39 39 import org.openstreetmap.josm.tools.CheckParameterUtil; 40 import org.openstreetmap.josm.tools.Utils; 40 41 41 42 /** … … 336 337 progressMonitor.setTicksCount(ids.size()); 337 338 progressMonitor.setTicks(0); 338 // The complete set contain g all primitives to fetch339 // The complete set containing all primitives to fetch 339 340 Set<Long> toFetch = new HashSet<>(ids); 340 341 // Build a list of fetchers that will download smaller sets containing only MAX_IDS_PER_REQUEST (200) primitives each. … … 342 343 int threadsNumber = Main.pref.getInteger("osm.download.threads", OsmApi.MAX_DOWNLOAD_THREADS); 343 344 threadsNumber = Math.min(Math.max(threadsNumber, 1), OsmApi.MAX_DOWNLOAD_THREADS); 344 Executor exec = Executors.newFixedThreadPool(threadsNumber );345 Executor exec = Executors.newFixedThreadPool(threadsNumber, Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY)); 345 346 CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec); 346 347 List<Future<FetchResult>> jobs = new ArrayList<>(); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r8540 r8734 813 813 try { 814 814 ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor); 815 ExecutorService service = Executors.newSingleThreadExecutor( );815 ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-loader-%d", Thread.NORM_PRIORITY)); 816 816 Future<?> future = service.submit(task); 817 817 try { … … 970 970 try { 971 971 monitor.beginTask(""); 972 ExecutorService service = Executors.newSingleThreadExecutor( );972 ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-updater-%d", Thread.NORM_PRIORITY)); 973 973 974 974 // try to download the plugin lists -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r8540 r8734 198 198 private static final Map<Image, Map<Long, ImageResource>> ROTATE_CACHE = new HashMap<>(); 199 199 200 private static final ExecutorService IMAGE_FETCHER = Executors.newSingleThreadExecutor(); 200 private static final ExecutorService IMAGE_FETCHER = 201 Executors.newSingleThreadExecutor(Utils.newThreadFactory("image-fetcher-%d", Thread.NORM_PRIORITY)); 201 202 202 203 /** -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r8650 r8734 47 47 import java.util.concurrent.Executors; 48 48 import java.util.concurrent.ThreadFactory; 49 import java.util.concurrent.atomic.AtomicLong; 49 50 import java.util.regex.Matcher; 50 51 import java.util.regex.Pattern; … … 1268 1269 1269 1270 /** 1271 * Creates a new {@link ThreadFactory} which creates threads with names according to {@code nameFormat}. 1272 * @param nameFormat a {@link String#format(String, Object...)} compatible name format; its first argument is a unique thread index 1273 * @param threadPriority the priority of the created threads, see {@link Thread#setPriority(int)} 1274 * @return a new {@link ThreadFactory} 1275 */ 1276 public static ThreadFactory newThreadFactory(final String nameFormat, final int threadPriority) { 1277 final String ignore = String.format(Locale.ENGLISH, nameFormat, 0);// fail fast 1278 return new ThreadFactory() { 1279 final AtomicLong count = new AtomicLong(0); 1280 @Override 1281 public Thread newThread(final Runnable runnable) { 1282 final Thread thread = new Thread(runnable, String.format(Locale.ENGLISH, nameFormat, count.getAndIncrement())); 1283 thread.setPriority(threadPriority); 1284 return thread; 1285 } 1286 }; 1287 } 1288 1289 /** 1270 1290 * Returns a pair containing the number of threads (n), and a thread pool (if n > 1) to perform 1271 1291 * multi-thread computation in the context of the given preference key. 1272 1292 * @param pref The preference key 1293 * @param nameFormat see {@link #newThreadFactory(String, int)} 1294 * @param threadPriority see {@link #newThreadFactory(String, int)} 1273 1295 * @return a pair containing the number of threads (n), and a thread pool (if n > 1, null otherwise) 1274 1296 * @since 7423 1275 1297 */ 1276 public static Pair<Integer, ExecutorService> newThreadPool(String pref ) {1298 public static Pair<Integer, ExecutorService> newThreadPool(String pref, String nameFormat, int threadPriority) { 1277 1299 int noThreads = Main.pref.getInteger(pref, Runtime.getRuntime().availableProcessors()); 1278 ExecutorService pool = noThreads <= 1 ? null : Executors.newFixedThreadPool(noThreads );1300 ExecutorService pool = noThreads <= 1 ? null : Executors.newFixedThreadPool(noThreads, newThreadFactory(nameFormat, threadPriority)); 1279 1301 return new Pair<>(noThreads, pool); 1280 1302 } … … 1427 1449 return hashMapInitialCapacity(nEntries, 0.75f); 1428 1450 } 1429 1430 /**1431 * @param name to be set for the threads1432 * @return Thread Factory returning named threads1433 */1434 public static ThreadFactory getNamedThreadFactory(final String name) {1435 return new ThreadFactory() {1436 @Override1437 public Thread newThread(Runnable r) {1438 Thread t = Executors.defaultThreadFactory().newThread(r);1439 t.setName(name);1440 return t;1441 }1442 };1443 }1444 1451 }
Note:
See TracChangeset
for help on using the changeset viewer.