Changeset 9351 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-01-09T15:41:47+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9297 r9351 51 51 import java.util.concurrent.ExecutorService; 52 52 import java.util.concurrent.Executors; 53 import java.util.concurrent.ForkJoinPool; 54 import java.util.concurrent.ForkJoinWorkerThread; 53 55 import java.util.concurrent.ThreadFactory; 54 56 import java.util.concurrent.atomic.AtomicLong; … … 1411 1413 1412 1414 /** 1413 * Returns a pair containing the number of threads (n), and a thread pool (if n > 1) to perform 1414 * multi-thread computation in the context of the given preference key. 1415 * @param pref The preference key 1415 * Returns a {@link ForkJoinPool} with the parallelism given by the preference key. 1416 * @param pref The preference key to determine parallelism 1416 1417 * @param nameFormat see {@link #newThreadFactory(String, int)} 1417 1418 * @param threadPriority see {@link #newThreadFactory(String, int)} 1418 * @return a pair containing the number of threads (n), and a thread pool (if n > 1, null otherwise) 1419 * @since 7423 1420 */ 1421 public static Pair<Integer, ExecutorService> newThreadPool(String pref, String nameFormat, int threadPriority) { 1419 * @return a {@link ForkJoinPool} 1420 */ 1421 public static ForkJoinPool newForkJoinPool(String pref, final String nameFormat, final int threadPriority) { 1422 1422 int noThreads = Main.pref.getInteger(pref, Runtime.getRuntime().availableProcessors()); 1423 ExecutorService pool = noThreads <= 1 ? null : Executors.newFixedThreadPool(noThreads, newThreadFactory(nameFormat, threadPriority)); 1424 return new Pair<>(noThreads, pool); 1423 return new ForkJoinPool(noThreads, new ForkJoinPool.ForkJoinWorkerThreadFactory() { 1424 final AtomicLong count = new AtomicLong(0); 1425 @Override 1426 public ForkJoinWorkerThread newThread(ForkJoinPool pool) { 1427 final ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool); 1428 thread.setName(String.format(Locale.ENGLISH, nameFormat, count.getAndIncrement())); 1429 thread.setPriority(threadPriority); 1430 return thread; 1431 } 1432 }, null, true); 1425 1433 } 1426 1434
Note:
See TracChangeset
for help on using the changeset viewer.