Package eu.simuline.octave.util
Class NamedThreadFactory
- java.lang.Object
-
- eu.simuline.octave.util.NamedThreadFactory
-
- All Implemented Interfaces:
ThreadFactory
public final class NamedThreadFactory extends Object implements ThreadFactory
A ThreadFactory that allows to create a thread from a runnable with a specific thread name.- Author:
- Kim Hansen
-
-
Field Summary
Fields Modifier and Type Field Description private ThreadGroup
group
The thread group from the security manager if it exists or else from the current thread.private String
namePrefix
The name prefix of the form<threadname>-javaoctave-<prefix>-<POOLNUMBER>-
, where<threadname>
is the name of the current thread,<prefix>
is the prefix given by a parameter of the constructorNamedThreadFactory(String)
and<POOLNUMBER>
isPOOL_NUMBER
depending on the factory object.private static AtomicInteger
POOL_NUMBER
This is initialized with 1 and read and incremented only if a factory object is created.private AtomicInteger
threadNumber
The number of the thread created next by this factory starting with one and being incremented by methodnewThread(Runnable)
.
-
Constructor Summary
Constructors Modifier Constructor Description NamedThreadFactory()
Creates a NamedThreadFactory viaNamedThreadFactory(String)
with name given by the simple class name ofOctaveExec
.private
NamedThreadFactory(String prefix)
Will create a factory that create Threads with the names:[parent]-javaoctave-[prefix]-[pool#]-[thread#]
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Thread
newThread(Runnable runnable)
Returns a new thread with standard priority which is no daemon with default priorityThread.NORM_PRIORITY
fromrunnable
with name consisting ofnamePrefix
and a running numberthreadNumber
.
-
-
-
Field Detail
-
POOL_NUMBER
private static final AtomicInteger POOL_NUMBER
This is initialized with 1 and read and incremented only if a factory object is created. It goes intonamePrefix
.
-
group
private final ThreadGroup group
The thread group from the security manager if it exists or else from the current thread. It is the group each thread belongs to created bynewThread(Runnable)
.
-
namePrefix
private final String namePrefix
The name prefix of the form<threadname>-javaoctave-<prefix>-<POOLNUMBER>-
, where<threadname>
is the name of the current thread,<prefix>
is the prefix given by a parameter of the constructorNamedThreadFactory(String)
and<POOLNUMBER>
isPOOL_NUMBER
depending on the factory object. The trailing-
is there because a new thread defined bynewThread(Runnable)
obtains a name consisting of the prefix followed bythreadNumber
.
-
threadNumber
private final AtomicInteger threadNumber
The number of the thread created next by this factory starting with one and being incremented by methodnewThread(Runnable)
.
-
-
Constructor Detail
-
NamedThreadFactory
private NamedThreadFactory(String prefix)
Will create a factory that create Threads with the names:[parent]-javaoctave-[prefix]-[pool#]-[thread#]
. Here,[parent]
is the name of the parent thread, i.e. of the current thread,[prefix]
is given by the parameter[pool#]
is the number of this factory and[thread#]
refers to the number of the thread created by this factory.- Parameters:
prefix
-
-
NamedThreadFactory
public NamedThreadFactory()
Creates a NamedThreadFactory viaNamedThreadFactory(String)
with name given by the simple class name ofOctaveExec
.
-
-
Method Detail
-
newThread
public Thread newThread(Runnable runnable)
Returns a new thread with standard priority which is no daemon with default priorityThread.NORM_PRIORITY
fromrunnable
with name consisting ofnamePrefix
and a running numberthreadNumber
.- Specified by:
newThread
in interfaceThreadFactory
- Parameters:
runnable
- the runnable to create a thread from.
-
-