Package pl.morgwai.base.utils.concurrent
Class NamingThreadFactory
- java.lang.Object
-
- pl.morgwai.base.utils.concurrent.NamingThreadFactory
-
- All Implemented Interfaces:
ThreadFactory
public class NamingThreadFactory extends Object implements ThreadFactory
A factory that names newThread
s based on constructor supplied generator/name. Each instance has an associated thread group, which newly created threads will belong to.
-
-
Constructor Summary
Constructors Constructor Description NamingThreadFactory(String name)
Constructs a factory that will create non-daemon threads withThread.NORM_PRIORITY
and names constructed using scheme<name>-thread-<sequenceNumber>
.NamingThreadFactory(ThreadGroup threadGroup, IntFunction<String> threadNameGenerator)
Constructs a factory that will create threads insidethreadGroup
with names constructed usingthreadNameGenerator
.
-
-
-
Constructor Detail
-
NamingThreadFactory
public NamingThreadFactory(String name)
Constructs a factory that will create non-daemon threads withThread.NORM_PRIORITY
and names constructed using scheme<name>-thread-<sequenceNumber>
. Created threads will belong to a newly createdThreadGroup
namedname
associated with this factory.
-
NamingThreadFactory
public NamingThreadFactory(ThreadGroup threadGroup, IntFunction<String> threadNameGenerator)
Constructs a factory that will create threads insidethreadGroup
with names constructed usingthreadNameGenerator
. Created threads will derive priority fromthreadGroup.getMaxPriority()
and daemon status fromthreadGroup.isDaemon()
.
-
-
Method Detail
-
newThread
public Thread newThread(Runnable task)
- Specified by:
newThread
in interfaceThreadFactory
-
-