ThreadFactory

An object that creates new threads on demand. Using thread factories removes hardwiring of calls to {@link Thread#Thread(Runnable) new Thread}, enabling applications to use special thread subclasses, priorities, etc.

<p> The simplest implementation of this interface is just: <pre> {@code class SimpleThreadFactory implements ThreadFactory { public Thread newThread(Runnable r) { return new Thread(r); } }}</pre>

The {@link Executors#defaultThreadFactory} method provides a more useful simple implementation, that sets the created thread context to known values before returning it. @author Doug Lea

Members

Functions

newThread
Thread newThread(Runnable r)

Constructs a new {@code Thread}. Implementations may also initialize priority, name, daemon status, {@code ThreadGroupEx}, etc.

Static functions

defaultThreadFactory
ThreadFactory defaultThreadFactory()

Returns a default thread factory used to create new threads. This factory creates all new threads used by an Executor in the same {@link ThreadGroupEx}. If there is a {@link java.lang.SecurityManager}, it uses the group of {@link System#getSecurityManager}, else the group of the thread invoking this {@code defaultThreadFactory} method. Each new thread is created as a non-daemon thread with priority set to the smaller of {@code Thread.PRIORITY_DEFAULT} and the maximum priority permitted in the thread group. New threads have names accessible via {@link Thread#getName} of <em>pool-N-thread-M</em>, where <em>N</em> is the sequence number of this factory, and <em>M</em> is the sequence number of the thread created by this factory. @return a thread factory

Meta