com.h3c.util

## Class NamedThreadFactory

- java.lang.Object
- - com.h3c.util.NamedThreadFactory

- All Implemented Interfaces:
    ThreadFactory

      public class NamedThreadFactory
      extends Object
      implements ThreadFactory

  Thread factory implementation that provides a distinct thread group name.

  Usage example:

       Executors.newSingleThreadExecutor(new NamedThreadFactory("MyThreads"));

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NamedThreadFactory(String groupName)` Constructor that creates a thread factory using the given group name.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ThreadFactory` | `namedThreads(String groupName)` Returns a named thread factory instance with the given group name.
    `Thread` | `newThread(Runnable r)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NamedThreadFactory

          public NamedThreadFactory(String groupName)

      Constructor that creates a thread factory using the given group name.
      Parameters:
        `groupName` - thread group prefix name

  - ### Method Detail

    - #### newThread

          public Thread newThread(Runnable r)

      Specified by:
        `newThread` in interface `ThreadFactory`

    - #### namedThreads

          public static ThreadFactory namedThreads(String groupName)

      Returns a named thread factory instance with the given group name.

      This convenience method, used with a static import, makes for more readable code:

           import static com.h3c.util.NamedThreadFactory.namedThreads;
           import static java.util.concurrent.Executors.newSingleThreadExecutor;
           ...
           ExecutorService es = newSingleThreadExecutor(namedThreads("MyThreads"));

      Parameters:
        `groupName` - the thread group name
      Returns:
        the thread factory

Copyright © 2014. All Rights Reserved.