Package org.threadly.concurrent
Class ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
- java.lang.Object
-
- org.threadly.concurrent.ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
-
- org.threadly.concurrent.ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
-
- Enclosing class:
- ThreadReferencingThreadFactory
public static class ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder extends ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
Builder for configuring a newThreadReferencingThreadFactory
. When ready invokebuild()
to construct the new factory.- Since:
- 5.39
-
-
Constructor Summary
Constructors Constructor Description ThreadReferencingThreadFactoryBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
appendPoolIdToPrefix(boolean appendPoolIdToPrefix)
Sets if a unique pool id should be appended to the prefix of thread names.ThreadReferencingThreadFactory
build()
Call to construct theThreadReferencingThreadFactory
when configuration is ready.ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
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.ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
threadNamePrefix(java.lang.String threadNamePrefix)
Call to set the prefix for newly created threads names.ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
threadPriority(int threadPriority)
Sets the priority associated to the thread.ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder
useDaemonThreads(boolean useDaemonThreads)
Sets of the created threads should be started with daemon status.
-
-
-
Method Detail
-
threadNamePrefix
public ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder threadNamePrefix(java.lang.String threadNamePrefix)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
Call to set the prefix for newly created threads names. By default this will be"pool-"
. SeeConfigurableThreadFactory.ConfigurableThreadFactoryBuilder.appendPoolIdToPrefix(boolean)
for determining the behavior of a pool ID following this prefix.- Overrides:
threadNamePrefix
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Parameters:
threadNamePrefix
- Prefix for thread name ornull
to use the default- Returns:
this
instance
-
appendPoolIdToPrefix
public ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder appendPoolIdToPrefix(boolean appendPoolIdToPrefix)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
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.- Overrides:
appendPoolIdToPrefix
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Parameters:
appendPoolIdToPrefix
- True to indicate an auto incrementing pool id should be included in the name- Returns:
this
instance
-
useDaemonThreads
public ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder useDaemonThreads(boolean useDaemonThreads)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
Sets of the created threads should be started with daemon status. By default threads will be started in daemon status.- Overrides:
useDaemonThreads
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Parameters:
useDaemonThreads
- True if started threads should be set as daemon- Returns:
this
instance
-
threadPriority
public ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder threadPriority(int threadPriority)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
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
.- Overrides:
threadPriority
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Parameters:
threadPriority
- The priority value to be set on new threads- Returns:
this
instance
-
exceptionHandler
public ThreadReferencingThreadFactory.ThreadReferencingThreadFactoryBuilder exceptionHandler(ExceptionHandler exceptionHandler)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
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.- Overrides:
exceptionHandler
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- 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)
Description copied from class:ConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
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.- Overrides:
onThreadCreation
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Parameters:
notifyThreadCreation
- Consumer to accept the Threads as they are created- Returns:
this
instance
-
build
public ThreadReferencingThreadFactory build()
Call to construct theThreadReferencingThreadFactory
when configuration is ready.- Overrides:
build
in classConfigurableThreadFactory.ConfigurableThreadFactoryBuilder
- Returns:
- Newly constructed ThreadFactory
-
-