public final class ThreadFactoryBuilder extends Object
If no backing thread factory is provided, a default backing thread factory is used as if by calling setThreadFactory(
Executors
)
.
Constructor and Description |
---|
ThreadFactoryBuilder()
Creates a new
ThreadFactory builder.
|
Modifier and Type | Method and Description |
---|---|
ThreadFactory |
build()
Returns a new thread factory using the options supplied during the building process.
|
ThreadFactoryBuilder |
setDaemon(boolean daemon)
Sets daemon or not for new threads created with this ThreadFactory.
|
ThreadFactoryBuilder |
setNameFormat(String
Sets the naming format to use when naming threads (
Thread ) which are created with this ThreadFactory.
|
ThreadFactoryBuilder |
setPriority(int priority)
Sets the priority for new threads created with this ThreadFactory.
|
ThreadFactoryBuilder |
setThreadFactory(ThreadFactory
Sets the backing
ThreadFactory for new threads created with this ThreadFactory.
|
ThreadFactoryBuilder |
setUncaughtExceptionHandler(Thread
Sets the
Thread.UncaughtExceptionHandler for new threads created with this ThreadFactory.
|
public ThreadFactoryBuilder()
ThreadFactory
builder.
public ThreadFactoryBuildersetNameFormat(String nameFormat)
Thread.setName(java.lang.String)
) which are created with this ThreadFactory.
nameFormat
- a
String.format(String, Object...)
-compatible format String, to which a unique integer (0, 1, etc.) will be supplied as the single parameter. This integer will be unique to the built instance of the ThreadFactory and will be assigned sequentially. For example,
"rpc-pool-%d"
will generate thread names like
"rpc-pool-0"
,
"rpc-pool-1"
,
"rpc-pool-2"
, etc.
public ThreadFactoryBuildersetDaemon(boolean daemon)
daemon
- whether or not new Threads created with this ThreadFactory will be daemon threads
public ThreadFactoryBuildersetPriority(int priority)
priority
- the priority for new Threads created with this ThreadFactory
public ThreadFactoryBuildersetUncaughtExceptionHandler(Thread .UncaughtExceptionHandler uncaughtExceptionHandler)
Thread.UncaughtExceptionHandler
for new threads created with this ThreadFactory.
uncaughtExceptionHandler
- the uncaught exception handler for new Threads created with this ThreadFactory
public ThreadFactoryBuildersetThreadFactory(ThreadFactory backingThreadFactory)
ThreadFactory
for new threads created with this ThreadFactory. Threads will be created by invoking #newThread(Runnable) on this backing
ThreadFactory
.
backingThreadFactory
- the backing
ThreadFactory
which will be delegated to during thread creation.
MoreExecutors
public ThreadFactorybuild()
ThreadFactory