Class ThreadFactoryBuilder
- java.lang.Object
- 
- com.google.common.util.concurrent.ThreadFactoryBuilder
 
- 
 @GwtIncompatible public final class ThreadFactoryBuilder extends java.lang.Object A ThreadFactory builder, providing any combination of these features:- whether threads should be marked as daemon threads
- a naming format
- a thread priority
- an uncaught exception handler
- a backing thread factory
 If no backing thread factory is provided, a default backing thread factory is used as if by calling setThreadFactory(Executors.defaultThreadFactory()).- Since:
- 4.0
- Author:
- Kurt Alfred Kluever
 
- 
- 
Constructor SummaryConstructors Constructor Description ThreadFactoryBuilder()Creates a newThreadFactorybuilder.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.ThreadFactorybuild()Returns a new thread factory using the options supplied during the building process.ThreadFactoryBuildersetDaemon(boolean daemon)Sets daemon or not for new threads created with this ThreadFactory.ThreadFactoryBuildersetNameFormat(java.lang.String nameFormat)Sets the naming format to use when naming threads (Thread.setName(java.lang.String)) which are created with this ThreadFactory.ThreadFactoryBuildersetPriority(int priority)Sets the priority for new threads created with this ThreadFactory.ThreadFactoryBuildersetThreadFactory(java.util.concurrent.ThreadFactory backingThreadFactory)Sets the backingThreadFactoryfor new threads created with this ThreadFactory.ThreadFactoryBuildersetUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)Sets theThread.UncaughtExceptionHandlerfor new threads created with this ThreadFactory.
 
- 
- 
- 
Constructor Detail- 
ThreadFactoryBuilderpublic ThreadFactoryBuilder() Creates a newThreadFactorybuilder.
 
- 
 - 
Method Detail- 
setNameFormat@CanIgnoreReturnValue public ThreadFactoryBuilder setNameFormat(java.lang.String nameFormat) Sets the naming format to use when naming threads (Thread.setName(java.lang.String)) which are created with this ThreadFactory.- Parameters:
- 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.
- Returns:
- this for the builder pattern
 
 - 
setDaemon@CanIgnoreReturnValue public ThreadFactoryBuilder setDaemon(boolean daemon) Sets daemon or not for new threads created with this ThreadFactory.- Parameters:
- daemon- whether or not new Threads created with this ThreadFactory will be daemon threads
- Returns:
- this for the builder pattern
 
 - 
setPriority@CanIgnoreReturnValue public ThreadFactoryBuilder setPriority(int priority) Sets the priority for new threads created with this ThreadFactory.Warning: relying on the thread scheduler is discouraged. - Parameters:
- priority- the priority for new Threads created with this ThreadFactory
- Returns:
- this for the builder pattern
 
 - 
setUncaughtExceptionHandler@CanIgnoreReturnValue public ThreadFactoryBuilder setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler) Sets theThread.UncaughtExceptionHandlerfor new threads created with this ThreadFactory.- Parameters:
- uncaughtExceptionHandler- the uncaught exception handler for new Threads created with this ThreadFactory
- Returns:
- this for the builder pattern
 
 - 
setThreadFactory@CanIgnoreReturnValue public ThreadFactoryBuilder setThreadFactory(java.util.concurrent.ThreadFactory backingThreadFactory) Sets the backingThreadFactoryfor new threads created with this ThreadFactory. Threads will be created by invoking #newThread(Runnable) on this backingThreadFactory.- Parameters:
- backingThreadFactory- the backing- ThreadFactorywhich will be delegated to during thread creation.
- Returns:
- this for the builder pattern
- See Also:
- MoreExecutors
 
 - 
buildpublic java.util.concurrent.ThreadFactory build() Returns a new thread factory using the options supplied during the building process. After building, it is still possible to change the options used to build the ThreadFactory and/or build again. State is not shared amongst built instances.- Returns:
- the fully constructed ThreadFactory
 
 
- 
 
-