Top Description Fields Constructors Methods
com.google.common.util.concurrent

public final Class ThreadFactoryBuilder

extends Object
Class Inheritance
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, java.util.Objects.requireNonNull

A ThreadFactory builder, providing any combination of these features:

If no backing thread factory is provided, a default backing thread factory is used as if by calling setThreadFactory(Executors#defaultThreadFactory()).

Author
Kurt Alfred Kluever
Since
4.0

Field Summary

Modifier and TypeField and Description
private ThreadFactory
private Boolean
private String
private Integer
private Thread.UncaughtExceptionHandler

Constructor Summary

AccessConstructor and Description
public
ThreadFactoryBuilder()

Creates a new ThreadFactory builder.

Method Summary

Modifier and TypeMethod and Description
public ThreadFactory

Returns:

the fully constructed ThreadFactory
build
()

Returns a new thread factory using the options supplied during the building process.

private static ThreadFactory
private static String
format(String format, Object... args)

public ThreadFactoryBuilder

Returns:

this for the builder pattern
setDaemon
(boolean
whether or not new Threads created with this ThreadFactory will be daemon threads
daemon
)

Sets daemon or not for new threads created with this ThreadFactory.

public ThreadFactoryBuilder

Returns:

this for the builder pattern
setNameFormat
(String
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.
nameFormat
)

Sets the naming format to use when naming threads (Thread#setName) which are created with this ThreadFactory.

public ThreadFactoryBuilder

Returns:

this for the builder pattern
setPriority
(int
the priority for new Threads created with this ThreadFactory
priority
)

Sets the priority for new threads created with this ThreadFactory.

public ThreadFactoryBuilder

Returns:

this for the builder pattern
setThreadFactory
(ThreadFactory
the backing ThreadFactory which will be delegated to during thread creation.
backingThreadFactory
)

Sets the backing ThreadFactory for new threads created with this ThreadFactory.

public ThreadFactoryBuilder

Returns:

this for the builder pattern
setUncaughtExceptionHandler
(Thread.UncaughtExceptionHandler
the uncaught exception handler for new Threads created with this ThreadFactory
uncaughtExceptionHandler
)

Sets the UncaughtExceptionHandler for new threads created with this ThreadFactory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backingThreadFactoryback to summary
private ThreadFactory backingThreadFactory
Annotations
@CheckForNull
daemonback to summary
private Boolean daemon
Annotations
@CheckForNull
nameFormatback to summary
private String nameFormat
Annotations
@CheckForNull
priorityback to summary
private Integer priority
Annotations
@CheckForNull
uncaughtExceptionHandlerback to summary
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler
Annotations
@CheckForNull

Constructor Detail

ThreadFactoryBuilderback to summary
public ThreadFactoryBuilder()

Creates a new ThreadFactory builder.

Method Detail

buildback to summary
public 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:ThreadFactory

the fully constructed ThreadFactory

doBuildback to summary
private static ThreadFactory doBuild(ThreadFactoryBuilder builder)
formatback to summary
private static String format(String format, Object... args)
setDaemonback to summary
public ThreadFactoryBuilder setDaemon(boolean daemon)

Sets daemon or not for new threads created with this ThreadFactory.

Parameters
daemon:boolean

whether or not new Threads created with this ThreadFactory will be daemon threads

Returns:ThreadFactoryBuilder

this for the builder pattern

Annotations
@CanIgnoreReturnValue
setNameFormatback to summary
public ThreadFactoryBuilder setNameFormat(String nameFormat)

Sets the naming format to use when naming threads (Thread#setName) which are created with this ThreadFactory.

Parameters
nameFormat:String

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:ThreadFactoryBuilder

this for the builder pattern

Annotations
@CanIgnoreReturnValue
setPriorityback to summary
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:int

the priority for new Threads created with this ThreadFactory

Returns:ThreadFactoryBuilder

this for the builder pattern

Annotations
@CanIgnoreReturnValue
setThreadFactoryback to summary
public ThreadFactoryBuilder setThreadFactory(ThreadFactory backingThreadFactory)

Sets the backing ThreadFactory for new threads created with this ThreadFactory. Threads will be created by invoking #newThread(Runnable) on this backing ThreadFactory.

Parameters
backingThreadFactory:ThreadFactory

the backing ThreadFactory which will be delegated to during thread creation.

Returns:ThreadFactoryBuilder

this for the builder pattern

Annotations
@CanIgnoreReturnValue
See Also
MoreExecutors
setUncaughtExceptionHandlerback to summary
public ThreadFactoryBuilder setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler)

Sets the UncaughtExceptionHandler for new threads created with this ThreadFactory.

Parameters
uncaughtExceptionHandler:Thread.UncaughtExceptionHandler

the uncaught exception handler for new Threads created with this ThreadFactory

Returns:ThreadFactoryBuilder

this for the builder pattern

Annotations
@CanIgnoreReturnValue