Java Thread Executor Create getExecutorServiceWithThreadName(final String threadNamePrefix, int threadCount)

Here you can find the source of getExecutorServiceWithThreadName(final String threadNamePrefix, int threadCount)

Description

get Executor Service With Thread Name

License

Open Source License

Declaration

public static ScheduledExecutorService getExecutorServiceWithThreadName(final String threadNamePrefix,
            int threadCount) 

Method Source Code


//package com.java2s;
/*/*  w  w  w  .ja v a  2s .c  o m*/
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

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

public class Main {
    public static ScheduledExecutorService getExecutorServiceWithThreadName(final String threadNamePrefix,
            int threadCount) {
        return Executors.newScheduledThreadPool(threadCount, new ThreadFactory() {

            private int i = 1;

            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(threadNamePrefix + ":" + i++);
                return thread;
            }
        });
    }
}

Related

  1. getExecutorService()
  2. getExecutorService()
  3. getExecutorService(int maximumPoolSize, int corePoolSize, long keepAliveTime, final String name, RejectedExecutionHandler rejectionPolicy)
  4. getExecutorService(int poolSize)
  5. getExecutorService(String usage)
  6. getExecutorThreadId(final ExecutorService executor)