Class ThreadFactoryBuilder
ThreadFactory instances. This builder is intended to be used for creating thread factories to
be used, e.g., when creating Executors 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 ThreadFactoryBuildercreate()Creates a freshThreadFactoryBuilder.withDaemonThreads(boolean daemonThreads) Sets whether theThreadFactorywill 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.UncaughtExceptionHandlerto 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
ThreadFactoryBuilderinstance
-
withName
Sets the name to be used by theThreadFactory.The threads created by the
ThreadFactoryare 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
ThreadFactoryBuilderinstance
-
withNamePrefix
Sets the name prefix to be used by theThreadFactory.The threads created by the
ThreadFactoryare 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
ThreadFactoryBuilderinstance
-
withDaemonThreads
Sets whether theThreadFactorywill create daemon threads. Defaults to false.- Parameters:
daemonThreads- indicates whether daemon threads shall be created- Returns:
- this
ThreadFactoryBuilderinstance
-
withUncaughtExceptionHandler
public ThreadFactoryBuilder withUncaughtExceptionHandler(@Nullable Thread.UncaughtExceptionHandler uncaughtExceptionHandler) Sets theThread.UncaughtExceptionHandlerto be used for created threads. If set to null, the builtThreadFactorywill not change the handler set by the wrappedThreadFactory. Defaults to null.- Parameters:
uncaughtExceptionHandler- TheThread.UncaughtExceptionHandlerto be use for created threads.- Returns:
- this
ThreadFactoryBuilderinstance
-
withPriority
Sets the priority to be set for created threads. Must be a valid thread priority, as indicated byThread.MIN_PRIORITYandThread.MAX_PRIORITY. If set to null, the builtThreadFactorywill not change the priority set by the wrappedThreadFactory. Defaults to null.- Parameters:
priority- The priority to be used for created threads.- Returns:
- this
ThreadFactoryBuilderinstance
-
build
Builds theThreadFactory, configuring it as specified.- Returns:
- the
ThreadFactory
-