Package org.threadly.concurrent
Class ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- java.lang.Object
-
- org.threadly.concurrent.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
-
- Direct Known Subclasses:
ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
- Enclosing class:
- ConfigurableThreadFactory
public static class ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder extends java.lang.Object
Builder for configuring a newConfigurableThreadFactory
. When ready invokebuild()
to construct the new factory.- Since:
- 5.39
-
-
Constructor Summary
Constructors Constructor Description ConfigurableThreadFactoryBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
appendPoolIdToPrefix(boolean appendPoolIdToPrefix)
Sets if a unique pool id should be appended to the prefix of thread names.ConfigurableThreadFactory
build()
Call to construct theConfigurableThreadFactory
when configuration is ready.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
exceptionHandler(ExceptionHandler exceptionHandler)
Sets anExceptionHandler
to be set for these newly created threads.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
onThreadCreation(java.util.function.Consumer<java.lang.Thread> notifyThreadCreation)
Sets aConsumer
which will be provided Thread references as they are created and before they are started.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
threadNamePrefix(java.lang.String threadNamePrefix)
Call to set the prefix for newly created threads names.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
threadPriority(int threadPriority)
Sets the priority associated to the thread.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
useDaemonThreads(boolean useDaemonThreads)
Sets of the created threads should be started with daemon status.
-
-
-
Method Detail
-
threadNamePrefix
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder threadNamePrefix(java.lang.String threadNamePrefix)
Call to set the prefix for newly created threads names. By default this will be"pool-"
. SeeappendPoolIdToPrefix(boolean)
for determining the behavior of a pool ID following this prefix.- Parameters:
threadNamePrefix
- Prefix for thread name ornull
to use the default- Returns:
this
instance
-
appendPoolIdToPrefix
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder appendPoolIdToPrefix(boolean appendPoolIdToPrefix)
Sets if a unique pool id should be appended to the prefix of thread names. By default this will append a pool id so that all threads are uniquely identifiable by name.- Parameters:
appendPoolIdToPrefix
- True to indicate an auto incrementing pool id should be included in the name- Returns:
this
instance
-
useDaemonThreads
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder useDaemonThreads(boolean useDaemonThreads)
Sets of the created threads should be started with daemon status. By default threads will be started in daemon status.- Parameters:
useDaemonThreads
- True if started threads should be set as daemon- Returns:
this
instance
-
threadPriority
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder threadPriority(int threadPriority)
Sets the priority associated to the thread. Depending on OS and JVM settings this priority may be ignored (see java documentation about thread priorities). This value should be betweenThread.MIN_PRIORITY
andThread.MAX_PRIORITY
.- Parameters:
threadPriority
- The priority value to be set on new threads- Returns:
this
instance
-
exceptionHandler
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder exceptionHandler(ExceptionHandler exceptionHandler)
Sets anExceptionHandler
to be set for these newly created threads. TypicallyExceptionUtils.setInheritableExceptionHandler(ExceptionHandler)
orExceptionUtils.setDefaultExceptionHandler(ExceptionHandler)
are better options. However this allows you to set anExceptionHandler
for threads specifically created from this ThreadFactory.- Parameters:
exceptionHandler
- Handler to be delegated to for errors in produced threads- Returns:
this
instance
-
onThreadCreation
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder onThreadCreation(java.util.function.Consumer<java.lang.Thread> notifyThreadCreation)
Sets aConsumer
which will be provided Thread references as they are created and before they are started. This can be useful when threads need to be provided to another library or code to monitor.- Parameters:
notifyThreadCreation
- Consumer to accept the Threads as they are created- Returns:
this
instance
-
build
public ConfigurableThreadFactory build()
Call to construct theConfigurableThreadFactory
when configuration is ready.- Returns:
- Newly constructed ThreadFactory
-
-