public class NamedThreadFactory extends Object implements ThreadFactory
ThreadFactory for ExecutorServices that names threads sequentially.
Creates Threads named with the prefix specified at construction time. Created threads
have the daemon bit set and priority Thread.MAX_PRIORITY.
An instance creates names with an instance-specific prefix suffixed with sequential integers.
Concurrency: See newThread(java.lang.Runnable).
| Constructor and Description |
|---|
NamedThreadFactory(String prefix)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Thread |
newThread(Runnable runnable)
Creates a sequentially named thread running a given Runnable.
|
public NamedThreadFactory(String prefix)
prefix - the string prefix that will be used to name threads created by this factorypublic Thread newThread(Runnable runnable)
The thread's name will be this instance's prefix concatenated with this instance's next* sequential integer.
Concurrency: Thread-safe.
(Concurrent calls get different numbers. Calls started after other calls complete get later/higher numbers than those other calls.
*However, for concurrent calls, the order of numbers is not defined.)
newThread in interface ThreadFactoryCopyright © 2021 The Apache Software Foundation. All rights reserved.