Package com.helger.base.concurrent
Class BasicThreadFactoryBuilder
java.lang.Object
com.helger.base.concurrent.BasicThreadFactoryBuilder
- All Implemented Interfaces:
IBuilder<BasicThreadFactory>,IResettableBuilder<BasicThreadFactory>
public class BasicThreadFactoryBuilder
extends Object
implements IResettableBuilder<BasicThreadFactory>
A builder class for creating instances of
BasicThreadFactory.
Using this builder class instances of BasicThreadFactory can be created and initialized.
The class provides methods that correspond to the configuration options supported by
BasicThreadFactory. Method chaining is supported. Refer to the documentation of
BasicThreadFactory for a usage example.
- Version:
- $Id: BasicThreadFactory.java 1583482 2014-03-31 22:54:57Z niallp $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull BasicThreadFactorybuild()Creates a newBasicThreadFactorywith all configuration options that have been specified by calling methods on this builder.final @NonNull BasicThreadFactoryBuilderdaemon(boolean bDaemon) Sets the daemon flag for the newBasicThreadFactory.final @NonNull BasicThreadFactoryBuildernamingPattern(@NonNull String sNamingPattern) Sets the naming pattern to be used by the newBasicThreadFactory.final @NonNull BasicThreadFactoryBuilderpriority(int nPriority) Sets the priority for the threads created by the newBasicThreadFactory.voidreset()Resets this builder.final @NonNull BasicThreadFactoryBuilderthreadGroup(@Nullable ThreadGroup aThreadGroup) Sets theThreadGroupto be used by the default thread factory.final @NonNull BasicThreadFactoryBuilderuncaughtExceptionHandler(@NonNull Thread.UncaughtExceptionHandler aExceptionHandler) Sets the uncaught exception handler for the threads created by the newBasicThreadFactory.final @NonNull BasicThreadFactoryBuilderwrappedFactory(@NonNull ThreadFactory aWrappedFactory) Sets theThreadFactoryto be wrapped by the newBasicThreadFactory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.helger.base.builder.IResettableBuilder
build
-
Constructor Details
-
BasicThreadFactoryBuilder
public BasicThreadFactoryBuilder()Create a new empty builder instance.
-
-
Method Details
-
wrappedFactory
public final @NonNull BasicThreadFactoryBuilder wrappedFactory(@NonNull ThreadFactory aWrappedFactory) Sets theThreadFactoryto be wrapped by the newBasicThreadFactory.- Parameters:
aWrappedFactory- the wrappedThreadFactory(must not be null)- Returns:
- this for chaining
- Throws:
NullPointerException- if the passed inThreadFactoryis null
-
threadGroup
Sets theThreadGroupto be used by the default thread factory. IfwrappedFactory(ThreadFactory)is used, this setting is useless.- Parameters:
aThreadGroup- theThreadGroupto use. May benull.- Returns:
- this for chaining
-
uncaughtExceptionHandler
public final @NonNull BasicThreadFactoryBuilder uncaughtExceptionHandler(@NonNull Thread.UncaughtExceptionHandler aExceptionHandler) Sets the uncaught exception handler for the threads created by the newBasicThreadFactory.- Parameters:
aExceptionHandler- theUncaughtExceptionHandler(must not be null)- Returns:
- this for chaining
- Throws:
NullPointerException- if the exception handler is null
-
namingPattern
Sets the naming pattern to be used by the newBasicThreadFactory. The formatting is done withString.format(String, Object...)using the thread counter (type long) as the only parameter.- Parameters:
sNamingPattern- the naming pattern (must not be null)- Returns:
- this for chaining
- Throws:
NullPointerException- if the naming pattern is null
-
priority
Sets the priority for the threads created by the newBasicThreadFactory.- Parameters:
nPriority- the priority- Returns:
- this for chaining
-
daemon
Sets the daemon flag for the newBasicThreadFactory. If this flag is set to true the new thread factory will create daemon threads.- Parameters:
bDaemon- the value of the daemon flag- Returns:
- this for chaining
-
reset
public void reset()Resets this builder. All configuration options are set to default values. Note: If thebuild()method was called, it is not necessary to callreset()explicitly because this is done automatically.- Specified by:
resetin interfaceIResettableBuilder<BasicThreadFactory>
-
build
Creates a newBasicThreadFactorywith all configuration options that have been specified by calling methods on this builder. After creating the factoryreset()is called.- Specified by:
buildin interfaceIBuilder<BasicThreadFactory>- Returns:
- the new
BasicThreadFactory
-