< prev index next >

src/java.base/share/classes/java/util/concurrent/ThreadFactory.java

Print this page

37 
38 /**
39  * An object that creates new threads on demand.  Using thread factories
40  * removes hardwiring of calls to {@link Thread#Thread(Runnable) new Thread},
41  * enabling applications to use special thread subclasses, priorities, etc.
42  *
43  * <p>
44  * The simplest implementation of this interface is just:
45  * <pre> {@code
46  * class SimpleThreadFactory implements ThreadFactory {
47  *   public Thread newThread(Runnable r) {
48  *     return new Thread(r);
49  *   }
50  * }}</pre>
51  *
52  * The {@link Executors#defaultThreadFactory} method provides a more
53  * useful simple implementation, that sets the created thread context
54  * to known values before returning it.
55  * @since 1.5
56  * @author Doug Lea

57  */
58 public interface ThreadFactory {
59 
60     /**
61      * Constructs a new {@code Thread}.  Implementations may also initialize
62      * priority, name, daemon status, {@code ThreadGroup}, etc.
63      *
64      * @param r a runnable to be executed by new thread instance
65      * @return constructed thread, or {@code null} if the request to
66      *         create a thread is rejected


67      */
68     Thread newThread(Runnable r);
69 }

37 
38 /**
39  * An object that creates new threads on demand.  Using thread factories
40  * removes hardwiring of calls to {@link Thread#Thread(Runnable) new Thread},
41  * enabling applications to use special thread subclasses, priorities, etc.
42  *
43  * <p>
44  * The simplest implementation of this interface is just:
45  * <pre> {@code
46  * class SimpleThreadFactory implements ThreadFactory {
47  *   public Thread newThread(Runnable r) {
48  *     return new Thread(r);
49  *   }
50  * }}</pre>
51  *
52  * The {@link Executors#defaultThreadFactory} method provides a more
53  * useful simple implementation, that sets the created thread context
54  * to known values before returning it.
55  * @since 1.5
56  * @author Doug Lea
57  * @see Thread.Builder#factory()
58  */
59 public interface ThreadFactory {
60 
61     /**
62      * Constructs a new {@code Thread}.  Implementations may also initialize
63      * priority, name, daemon status, {@code ThreadGroup}, etc.
64      *
65      * @param r a runnable to be executed by new thread instance
66      * @return constructed thread, or {@code null} if the request to
67      *         create a thread is rejected
68      *
69      * @see <a href="../../lang/Thread.html#inheritance">Inheritance</a>
70      */
71     Thread newThread(Runnable r);
72 }
< prev index next >