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.ObjectBuilder 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.ConfigurableThreadFactoryBuilderappendPoolIdToPrefix(boolean appendPoolIdToPrefix)Sets if a unique pool id should be appended to the prefix of thread names.ConfigurableThreadFactorybuild()Call to construct theConfigurableThreadFactorywhen configuration is ready.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilderexceptionHandler(ExceptionHandler exceptionHandler)Sets anExceptionHandlerto be set for these newly created threads.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilderonThreadCreation(java.util.function.Consumer<java.lang.Thread> notifyThreadCreation)Sets aConsumerwhich will be provided Thread references as they are created and before they are started.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilderthreadNamePrefix(java.lang.String threadNamePrefix)Call to set the prefix for newly created threads names.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilderthreadPriority(int threadPriority)Sets the priority associated to the thread.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilderuseDaemonThreads(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 ornullto use the default- Returns:
thisinstance
-
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:
thisinstance
-
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:
thisinstance
-
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_PRIORITYandThread.MAX_PRIORITY.- Parameters:
threadPriority- The priority value to be set on new threads- Returns:
thisinstance
-
exceptionHandler
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder exceptionHandler(ExceptionHandler exceptionHandler)
Sets anExceptionHandlerto be set for these newly created threads. TypicallyExceptionUtils.setInheritableExceptionHandler(ExceptionHandler)orExceptionUtils.setDefaultExceptionHandler(ExceptionHandler)are better options. However this allows you to set anExceptionHandlerfor threads specifically created from this ThreadFactory.- Parameters:
exceptionHandler- Handler to be delegated to for errors in produced threads- Returns:
thisinstance
-
onThreadCreation
public ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder onThreadCreation(java.util.function.Consumer<java.lang.Thread> notifyThreadCreation)
Sets aConsumerwhich 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:
thisinstance
-
build
public ConfigurableThreadFactory build()
Call to construct theConfigurableThreadFactorywhen configuration is ready.- Returns:
- Newly constructed ThreadFactory
-
-