Here you can find the source of createDaemonThreadFactory(final int threadPriority, final ThreadGroup group, final ClassLoader contextClassLoader)
Parameter | Description |
---|---|
threadPriority | The priority of all threads which created by returned factory. |
group | Thread group for all threads which created by returned factory. May be null . |
contextClassLoader | The context class loader used by all threads which created by returned factory. May be null . |
public static ThreadFactory createDaemonThreadFactory(final int threadPriority, final ThreadGroup group, final ClassLoader contextClassLoader)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.*; public class Main { /**//from w w w.j a va 2 s . c o m * Creates a new instance of the thread factory with given thread instantiation parameters. * <p> * The returned factory always creates daemon threads. For more information, see {@link Thread#setDaemon(boolean)}. * </p> * @param threadPriority The priority of all threads which created by returned factory. * @param group Thread group for all threads which created by returned factory. May be {@literal null}. * @param contextClassLoader The context class loader used by all threads which created by returned factory. May be {@literal null}. * @return A new instance of the thread factory. */ public static ThreadFactory createDaemonThreadFactory(final int threadPriority, final ThreadGroup group, final ClassLoader contextClassLoader) { return r -> { final Thread t = new Thread(group, r); t.setDaemon(true); t.setPriority(threadPriority); t.setContextClassLoader(contextClassLoader); return t; }; } /** * Creates a new instance of the thread factory with given thread instantiation parameters. * <p> * The returned factory always creates daemon threads. For more information, see {@link Thread#setDaemon(boolean)}. * </p> * @param threadPriority The priority of all threads which created by returned factory. * @param group Thread group for all threads which created by returned factory. May be {@literal null}. * @return A new instance of the thread factory. */ public static ThreadFactory createDaemonThreadFactory(final int threadPriority, final ThreadGroup group) { return createDaemonThreadFactory(threadPriority, group, Thread.currentThread().getContextClassLoader()); } }