Changeset 8734 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2015-09-08T15:20:34+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.