Java Thread Executor Create createDefaultExecutorService(final String threadNamePrefix, final int parallel)

Here you can find the source of createDefaultExecutorService(final String threadNamePrefix, final int parallel)

Description

Returns a new thread pool configured with the default settings.

License

Open Source License

Parameter

Parameter Description
threadNamePrefix prefix of the thread name
parallel the number of concurrency

Return

A new thread pool configured with the default settings.

Declaration

static public ThreadPoolExecutor createDefaultExecutorService(final String threadNamePrefix,
        final int parallel) 

Method Source Code

//package com.java2s;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;

public class Main {
    /**/* w  w w  . j  a va  2s . c  o  m*/
     * Returns a new thread pool configured with the default settings.
     *
     * @param threadNamePrefix prefix of the thread name
     * @param parallel         the number of concurrency
     * @return A new thread pool configured with the default settings.
     */
    static public ThreadPoolExecutor createDefaultExecutorService(final String threadNamePrefix,
            final int parallel) {
        ThreadFactory threadFactory = new ThreadFactory() {
            private int threadCount = 1;

            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(threadNamePrefix + threadCount++);
                return thread;
            }
        };
        return (ThreadPoolExecutor) Executors.newFixedThreadPool(parallel, threadFactory);
    }
}

Related

  1. createDaemonThreadFactory()
  2. createDefaultExecutorService()
  3. createEventsOrderedDeliveryExecutor()
  4. createExecutor()
  5. createExecutor(final String file)
  6. createExecutors(int numThreads)