Class ThreadFactoryBuilder
ThreadFactory
instances. This builder is intended to be used for creating thread factories to
be used, e.g., when creating Executor
s via the Executors
utility methods.
The built ThreadFactory
uses a wrapped ThreadFactory
to create threads (defaulting to
Executors.defaultThreadFactory()
, and then overwrites thread properties as indicated in the build process.
- Author:
- Henning Sudbrock - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds theThreadFactory
, configuring it as specified.static ThreadFactoryBuilder
create()
Creates a freshThreadFactoryBuilder
.withDaemonThreads
(boolean daemonThreads) Sets whether theThreadFactory
will create daemon threads.Sets the name to be used by theThreadFactory
.withNamePrefix
(@Nullable String namePrefix) Sets the name prefix to be used by theThreadFactory
.withPriority
(@Nullable Integer priority) Sets the priority to be set for created threads.withUncaughtExceptionHandler
(@Nullable Thread.UncaughtExceptionHandler uncaughtExceptionHandler) Sets theThread.UncaughtExceptionHandler
to be used for created threads.withWrappedThreadFactory
(@Nullable ThreadFactory wrappedThreadFactory) Sets the wrapped thread factory used to create threads.
-
Method Details
-
create
Creates a freshThreadFactoryBuilder
.- Returns:
- A
ThreadFactoryBuilder
-
withWrappedThreadFactory
Sets the wrapped thread factory used to create threads.If set to null,
Executors.defaultThreadFactory()
is used.Defaults to null.
- Parameters:
wrappedThreadFactory
- the wrapped thread factory to be used- Returns:
- this
ThreadFactoryBuilder
instance
-
withName
Sets the name to be used by theThreadFactory
.The threads created by the
ThreadFactory
are named 'namePrefix-name-i', where i is an integer incremented with each new thread, initialized to 1.If the name is set to null, the created threads are named 'namePrefix-generatedName', where 'generatedName' is the name generated by the wrapped thread factory.
Defaults to null.
- Parameters:
name
- The name (can be null)- Returns:
- this
ThreadFactoryBuilder
instance
-
withNamePrefix
Sets the name prefix to be used by theThreadFactory
.The threads created by the
ThreadFactory
are named 'namePrefix-name-i', where i is an integer incremented with each new thread, initialized to 1. If set to null, threads are named 'name-i'.Defaults to the name prefix 'OH'. Setting a name prefix different than the default one is intended to be used by solutions integrating openHAB.
- Parameters:
namePrefix
- The name prefix (can be null)- Returns:
- this
ThreadFactoryBuilder
instance
-
withDaemonThreads
Sets whether theThreadFactory
will create daemon threads. Defaults to false.- Parameters:
daemonThreads
- indicates whether daemon threads shall be created- Returns:
- this
ThreadFactoryBuilder
instance
-
withUncaughtExceptionHandler
public ThreadFactoryBuilder withUncaughtExceptionHandler(@Nullable Thread.UncaughtExceptionHandler uncaughtExceptionHandler) Sets theThread.UncaughtExceptionHandler
to be used for created threads. If set to null, the builtThreadFactory
will not change the handler set by the wrappedThreadFactory
. Defaults to null.- Parameters:
uncaughtExceptionHandler
- TheThread.UncaughtExceptionHandler
to be use for created threads.- Returns:
- this
ThreadFactoryBuilder
instance
-
withPriority
Sets the priority to be set for created threads. Must be a valid thread priority, as indicated byThread.MIN_PRIORITY
andThread.MAX_PRIORITY
. If set to null, the builtThreadFactory
will not change the priority set by the wrappedThreadFactory
. Defaults to null.- Parameters:
priority
- The priority to be used for created threads.- Returns:
- this
ThreadFactoryBuilder
instance
-
build
Builds theThreadFactory
, configuring it as specified.- Returns:
- the
ThreadFactory
-