Java Thread Factory getThreadFactory(String name)

Here you can find the source of getThreadFactory(String name)

Description

Based on the default thread factory

License

Open Source License

Parameter

Parameter Description
name the name prefix of the new thread

Return

the factory to use when creating new threads

Declaration

public static final ThreadFactory getThreadFactory(String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Weasis Team 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
 *
 * Contributors://from   ww  w. ja va  2 s.  c  o  m
 *     Nicolas Roduit - initial API and implementation
 *******************************************************************************/

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

public class Main {
    /**
     * Based on the default thread factory
     *
     * @param name
     *            the name prefix of the new thread
     * @return the factory to use when creating new threads
     */
    public static final ThreadFactory getThreadFactory(String name) {
        return r -> {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setName(name + "-" + t.getName()); //$NON-NLS-1$
            return t;
        };
    }
}

Related

  1. getScheduledExecutorService( final int maxNbThreads, final String name)
  2. getThreadFactory(String nameFormat, boolean daemon)