Package com.kristensoft.kdc
Class NamedThreadFactory
- java.lang.Object
-
- com.kristensoft.kdc.NamedThreadFactory
-
- All Implemented Interfaces:
ThreadFactory
public final class NamedThreadFactory extends Object implements ThreadFactory
Creates threads with unique, sequentially numbered names.Each thread is assigned a name consisting of a base name followed by a hyphen and an incrementing number, beginning with
1.The thread counter is maintained independently for each factory instance and is safe for concurrent use.
- Author:
- Charles B. Kozoyed
-
-
Constructor Summary
Constructors Constructor Description NamedThreadFactory(String baseName)Constructs a thread factory using the specified base name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadnewThread(Runnable runnable)Creates a new thread for executing the specified task.
-
-
-
Constructor Detail
-
NamedThreadFactory
public NamedThreadFactory(String baseName)
Constructs a thread factory using the specified base name.- Parameters:
baseName- the base name assigned to threads created by this factory- Throws:
IllegalArgumentException- if the base name isnullor blank
-
-
Method Detail
-
newThread
public Thread newThread(Runnable runnable)
Creates a new thread for executing the specified task.The thread is assigned a unique name in the format
baseName-N, whereNis a sequential number starting at1.The returned thread is not started.
- Specified by:
newThreadin interfaceThreadFactory- Parameters:
runnable- the task to execute in the new thread- Returns:
- a new, unstarted thread with a sequentially numbered name
-
-