Class NamedThreadFactory

  • All Implemented Interfaces:
    java.util.concurrent.ThreadFactory

    public class NamedThreadFactory
    extends java.lang.Object
    implements java.util.concurrent.ThreadFactory
    ThreadFactory which creates named threads for use in an ExecutorService. Each factory has a pool name and threads in the pool will have the name "poolName-X-thread-Y". If multiple factories are created with the same poolName then each will get its own unique number "X". For example, if two pools were created with the name "workers" then you would see threads like "workers-1-thread-1" and "workers-2-thread-1".
    • Constructor Summary

      Constructors 
      Constructor Description
      NamedThreadFactory​(java.lang.String poolName)
      Construct a new NamedThreadFactory with the given pool name.
      NamedThreadFactory​(java.lang.ThreadGroup threadGroup, java.lang.String poolName)
      Construct a new NamedThreadFactory with the given thread group and pool name.
      NamedThreadFactory​(java.util.concurrent.ThreadFactory threadFactory, java.lang.String poolName)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Thread init​(java.lang.Thread t)  
      java.lang.Thread newThread​(java.lang.Runnable runnable)
      Create a new Thread for the specified Runnable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NamedThreadFactory

        public NamedThreadFactory​(java.lang.String poolName)
        Construct a new NamedThreadFactory with the given pool name.
        Parameters:
        poolName - the name to be used as part of the prefix for this factory.
      • NamedThreadFactory

        public NamedThreadFactory​(java.lang.ThreadGroup threadGroup,
                                  java.lang.String poolName)
        Construct a new NamedThreadFactory with the given thread group and pool name.
        Parameters:
        threadGroup - the thread group which the new threads belong.
        poolName - the name to be used as part of the prefix for this factory.
      • NamedThreadFactory

        public NamedThreadFactory​(java.util.concurrent.ThreadFactory threadFactory,
                                  java.lang.String poolName)
    • Method Detail

      • newThread

        public java.lang.Thread newThread​(@Nonnull
                                          java.lang.Runnable runnable)
        Create a new Thread for the specified Runnable.
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory
        Parameters:
        runnable - the Runnable to be executed by the new thread.
        Returns:
        a new Thread instance
      • init

        protected java.lang.Thread init​(java.lang.Thread t)