Example usage for java.util.concurrent ForkJoinWorkerThread setName

List of usage examples for java.util.concurrent ForkJoinWorkerThread setName

Introduction

In this page you can find the example usage for java.util.concurrent ForkJoinWorkerThread setName.

Prototype

public final synchronized void setName(String name) 

Source Link

Document

Changes the name of this thread to be equal to the argument name .

Usage

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Returns a {@link ForkJoinPool} with the parallelism given by the preference key.
 * @param pref The preference key to determine parallelism
 * @param nameFormat see {@link #newThreadFactory(String, int)}
 * @param threadPriority see {@link #newThreadFactory(String, int)}
 * @return a {@link ForkJoinPool}/*from w  ww.  j  a v  a 2 s. c o  m*/
 */
public static ForkJoinPool newForkJoinPool(String pref, final String nameFormat, final int threadPriority) {
    int noThreads = Main.pref.getInteger(pref, Runtime.getRuntime().availableProcessors());
    return new ForkJoinPool(noThreads, new ForkJoinPool.ForkJoinWorkerThreadFactory() {
        final AtomicLong count = new AtomicLong(0);

        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            thread.setName(String.format(Locale.ENGLISH, nameFormat, count.getAndIncrement()));
            thread.setPriority(threadPriority);
            return thread;
        }
    }, null, true);
}