Package org.jivesoftware.util
Class NamedThreadFactory
- java.lang.Object
-
- org.jivesoftware.util.NamedThreadFactory
-
- All Implemented Interfaces:
ThreadFactory
public class NamedThreadFactory extends Object implements ThreadFactory
A thread factory that allows threads to be named. An instance will either create new Threads, or use use a delegate Thread Factory. When a new thread is generated, the name of the generated thread is replaced by concatenation of the provided thread name prefix (which is an other argument of the constructor) and a sequence number. Sequence numbers are guaranteed to be unique for threads generated by the same instance of this class. Optionally, this implementation allows the priority, isDaemon and threadGroup and stackSize value of the generated threads to be set/overridden. Note that the threadGroup and stackSize value cannot be overridden when a delegate thread factory is used. This implementation is thread safe when the provided delegate is thread safe.- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
-
-
Constructor Summary
Constructors Constructor Description NamedThreadFactory(String threadNamePrefix, Boolean daemon, Integer priority, ThreadGroup threadGroup, Long stackSize)
Constructs a thread factory that will create new Thread instances (as opposed to using a delegate thread factory).NamedThreadFactory(String threadNamePrefix, ThreadFactory delegate, Boolean daemon, Integer priority)
Constructs an instance that delegates thread creation to the thread factory passed as an argument.
-
-
-
Constructor Detail
-
NamedThreadFactory
public NamedThreadFactory(String threadNamePrefix, ThreadFactory delegate, Boolean daemon, Integer priority)
Constructs an instance that delegates thread creation to the thread factory passed as an argument. When the delegate argument is null, the instance will instantiate threads itself (similar to the functionality of the other constructor of this class). When null is provided for the optional arguments of this method, the values as defined by the delegate factory are used.- Parameters:
threadNamePrefix
- The prefix of the name for new threads (cannot be null or an empty string).delegate
- The factory to which this implementation delegates to (null when no override is desired).daemon
- override for the isDaemon value for new threads (null when no override is desired).priority
- override for the priority value for new threads (null when no override is desired).
-
NamedThreadFactory
public NamedThreadFactory(String threadNamePrefix, Boolean daemon, Integer priority, ThreadGroup threadGroup, Long stackSize)
Constructs a thread factory that will create new Thread instances (as opposed to using a delegate thread factory). When null is provided for the optional arguments of this method, default values as provided by the Thread class implementation will be used.- Parameters:
threadNamePrefix
- The prefix of the name for new threads (cannot be null or an empty string).daemon
- the isDaemon value for new threads (null to use default value).priority
- override for the priority value for new threads (null to use default value).threadGroup
- override for the thread group (null to use default value).stackSize
- override for the stackSize value for new threads (null to use default value).
-
-
Method Detail
-
newThread
public Thread newThread(Runnable runnable)
- Specified by:
newThread
in interfaceThreadFactory
-
-