| ThreadFactory.java |
1 /*
2 * %W% %E%
3 *
4 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
5 * ORACLE 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 {@code Thread}. Implementations may also initialize
35 * priority, name, daemon status, {@code ThreadGroup}, etc.
36 *
37 * @param r a runnable to be executed by new thread instance
38 * @return constructed thread, or {@code null} if the request to
39 * create a thread is rejected
40 */
41 Thread newThread(Runnable r);
42 }
43