Class ThreadFactoryBuilder
- java.lang.Object
-
- dk.cloudcreate.essentials.shared.concurrent.ThreadFactoryBuilder
-
public class ThreadFactoryBuilder extends Object
Builder for aThreadFactoryto allow setting thread names, auto increment thread numbers, etc.
-
-
Constructor Summary
Constructors Constructor Description ThreadFactoryBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadFactorybuild()Create theThreadFactorybased on the builder settingsstatic ThreadFactoryBuilderbuilder()Create a new builderThreadFactoryBuilderdaemon(boolean daemon)Set if theThread's created by the resultingThreadFactoryare daemon threadsThreadFactoryBuilderdelegateThreadFactory(ThreadFactory delegateThreadFactory)Set theThreadFactorythat will generate newThread's.ThreadFactoryBuildernameFormat(String nameFormat)Set the name format for generated thread names.ThreadFactoryBuilderpriority(int priority)Set the priority of theThread's generated by the resultingThreadFactoryThreadFactoryBuilderuncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler)Set theThread.UncaughtExceptionHandlerfor theThread's created by the resultingThreadFactoryare daemon threads
-
-
-
Method Detail
-
builder
public static ThreadFactoryBuilder builder()
Create a new builder- Returns:
- the new builder
-
build
public ThreadFactory build()
Create theThreadFactorybased on the builder settings- Returns:
- the
ThreadFactory
-
nameFormat
public ThreadFactoryBuilder nameFormat(String nameFormat)
Set the name format for generated thread names. The format supports using %d as the placeholder for the thread number (every thread created by the resultingThreadFactorywill automatically receive sequential increasing thread number).
Example: "polling-process-%d" or "%d-connection-pool"- Parameters:
nameFormat- the name format- Returns:
- this
ThreadFactoryBuilderinstance
-
delegateThreadFactory
public ThreadFactoryBuilder delegateThreadFactory(ThreadFactory delegateThreadFactory)
Set theThreadFactorythat will generate newThread's. If none is specified theExecutors.defaultThreadFactory()will be used- Parameters:
delegateThreadFactory- the underlyingThreadFactory- Returns:
- this
ThreadFactoryBuilderinstance
-
priority
public ThreadFactoryBuilder priority(int priority)
Set the priority of theThread's generated by the resultingThreadFactory- Parameters:
priority- the priority of theThread's created. Min value isThread.MIN_PRIORITYand max value isThread.MAX_PRIORITY- Returns:
- this
ThreadFactoryBuilderinstance
-
daemon
public ThreadFactoryBuilder daemon(boolean daemon)
Set if theThread's created by the resultingThreadFactoryare daemon threads- Parameters:
daemon- should theThread's created be daemon threads- Returns:
- this
ThreadFactoryBuilderinstance
-
uncaughtExceptionHandler
public ThreadFactoryBuilder uncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Set theThread.UncaughtExceptionHandlerfor theThread's created by the resultingThreadFactoryare daemon threads- Parameters:
uncaughtExceptionHandler- theThread.UncaughtExceptionHandlerfor theThread's created- Returns:
- this
ThreadFactoryBuilderinstance
-
-