Class 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 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 into namePrefix.
      • 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 by newThread(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 constructor NamedThreadFactory(String) and <POOLNUMBER> is POOL_NUMBER depending on the factory object. The trailing - is there because a new thread defined by newThread(Runnable) obtains a name consisting of the prefix followed by threadNumber.
      • threadNumber

        private final AtomicInteger threadNumber
        The number of the thread created next by this factory starting with one and being incremented by method newThread(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 -