public class NamedThreadFactory extends Object implements ThreadFactory
Usage example:
Executors.newSingleThreadExecutor(new NamedThreadFactory("MyThreads"));
| Constructor and Description |
|---|
NamedThreadFactory(String groupName)
Constructor that creates a thread factory using the given group name.
|
| Modifier and Type | Method and Description |
|---|---|
static ThreadFactory |
namedThreads(String groupName)
Returns a named thread factory instance with the given group name.
|
Thread |
newThread(Runnable r) |
public NamedThreadFactory(String groupName)
groupName - thread group prefix namepublic Thread newThread(Runnable r)
newThread in interface ThreadFactorypublic static ThreadFactory namedThreads(String groupName)
This convenience method, used with a static import, makes for more readable code:
import static com.h3c.util.NamedThreadFactory.namedThreads;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
...
ExecutorService es = newSingleThreadExecutor(namedThreads("MyThreads"));
groupName - the thread group nameCopyright © 2014. All Rights Reserved.