Package org.marketcetera.util.misc
Class NamedThreadFactory
- java.lang.Object
-
- org.marketcetera.util.misc.NamedThreadFactory
-
- All Implemented Interfaces:
ThreadFactory
public class NamedThreadFactory extends Object implements ThreadFactory
A Thread factory that creates threads whose names begin with a specified prefix. If the specified prefix isfoo, the threads created by this factory will have names that look likefooXwhere 'X' is a monotonically increasing number used to name each thread created by this factory uniquely.The factory delegates the thread creation to
Executors.defaultThreadFactory(). After the thread has been created by the delegated factory, this class simply resets their name to the desired value.- Since:
- 2.0.0
- Version:
- $Id: NamedThreadFactory.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- anshul@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description private ThreadFactorymDelegateprivate StringmNamePrefixprivate AtomicIntegermThreadNumber
-
Constructor Summary
Constructors Constructor Description NamedThreadFactory(String inNamePrefix)Creates an instance that will create threads whose names begin with the specified prefix.
-
-
-
Field Detail
-
mNamePrefix
private final String mNamePrefix
-
mThreadNumber
private final AtomicInteger mThreadNumber
-
mDelegate
private final ThreadFactory mDelegate
-
-
Constructor Detail
-
NamedThreadFactory
public NamedThreadFactory(String inNamePrefix)
Creates an instance that will create threads whose names begin with the specified prefix.- Parameters:
inNamePrefix- the prefix to use for naming every thread created by this factory. Cannot be null.
-
-
Method Detail
-
newThread
public Thread newThread(Runnable r)
- Specified by:
newThreadin interfaceThreadFactory
-
-