Example usage for java.util.concurrent ForkJoinWorkerThread setPriority

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

Introduction

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

Prototype

public final void setPriority(int newPriority) 

Source Link

Document

Changes the priority of this thread.

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  ww w  .  ja  va  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);
}