1 /* 2 * @(#)ThreadFactory.java 1.4 04/01/12 3 * 4 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 */ 7 8 package java.util.concurrent; 9 10 /** 11 * An object that creates new threads on demand. Using thread factories 12 * removes hardwiring of calls to {@link Thread#Thread(Runnable) new Thread}, 13 * enabling applications to use special thread subclasses, priorities, etc. 14 * 15 * <p> 16 * The simplest implementation of this interface is just: 17 * <pre> 18 * class SimpleThreadFactory implements ThreadFactory { 19 * public Thread newThread(Runnable r) { 20 * return new Thread(r); 21 * } 22 * } 23 * </pre> 24 * 25 * The {@link Executors#defaultThreadFactory} method provides a more 26 * useful simple implementation, that sets the created thread context 27 * to known values before returning it. 28 * @since 1.5 29 * @author Doug Lea 30 */ 31 public interface ThreadFactory { 32 33 /** 34 * Constructs a new <tt>Thread</tt>. Implementations may also initialize 35 * priority, name, daemon status, <tt>ThreadGroup</tt>, etc. 36 * 37 * @param r a runnable to be executed by new thread instance 38 * @return constructed thread 39 */ 40 Thread newThread(Runnable r); 41 } 42