Class DaemonFactory

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

    public class DaemonFactory
    extends java.lang.Object
    implements java.util.concurrent.ThreadFactory
    The DaemonFactory object is used to build threads and prefix the thread with a type name. Prefixing the threads with the type that it represents allows the purpose of the thread to be determined and also provides better debug information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class type
      This is the type of the task this pool will execute.
    • Constructor Summary

      Constructors 
      Constructor Description
      DaemonFactory()
      Constructor for the DaemonFactory object.
      DaemonFactory​(java.lang.Class type)
      Constructor for the DaemonFactory object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String createName​(java.lang.Class type, java.lang.Thread thread)
      This will create a thread name that is unique.
      private java.lang.String createName​(java.lang.Runnable task, java.lang.Thread thread)
      This will create a thread name that is unique.
      private java.lang.Thread createThread​(java.lang.Runnable task)
      This is used to create the thread that will be used to execute the provided task.
      java.lang.Thread newThread​(java.lang.Runnable task)
      This is used to create a thread from the provided runnable.
      java.lang.Thread newThread​(java.lang.Runnable task, java.lang.Class type)
      This is used to create a thread from the provided runnable.
      • Methods inherited from class java.lang.Object

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

      • type

        private final java.lang.Class type
        This is the type of the task this pool will execute.
    • Constructor Detail

      • DaemonFactory

        public DaemonFactory()
        Constructor for the DaemonFactory object. This will provide a thread factory that names the threads based on the type of Runnable the pool executes.
      • DaemonFactory

        public DaemonFactory​(java.lang.Class type)
        Constructor for the DaemonFactory object. This will provide a thread factory that names the threads based on the type of Runnable the pool executes. Each of the threads is given a unique sequence number.
        Parameters:
        type - this is the type of runnable this will execute
    • Method Detail

      • newThread

        public java.lang.Thread newThread​(java.lang.Runnable task)
        This is used to create a thread from the provided runnable. The thread created will contain a unique name which is prefixed with the type of task it has been created to execute. This provides some detail as to what the thread should be doing.
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory
        Parameters:
        task - this is the task that the thread is to execute
        Returns:
        this returns a thread that will executed the given task
      • newThread

        public java.lang.Thread newThread​(java.lang.Runnable task,
                                          java.lang.Class type)
        This is used to create a thread from the provided runnable. The thread created will contain a unique name which is prefixed with the type of task it has been created to execute. This provides some detail as to what the thread should be doing.
        Parameters:
        task - this is the task that the thread is to execute
        type - this is the type of object the thread is to execute
        Returns:
        this returns a thread that will executed the given task
      • createName

        private java.lang.String createName​(java.lang.Runnable task,
                                            java.lang.Thread thread)
        This will create a thread name that is unique. The thread name is a combination of the original thread name with a prefix of the type of the object that will be running within it.
        Parameters:
        task - this is the task to be run within the thread
        thread - this is the thread containing the original name
        Returns:
        this will return the new name of the thread
      • createName

        private java.lang.String createName​(java.lang.Class type,
                                            java.lang.Thread thread)
        This will create a thread name that is unique. The thread name is a combination of the original thread name with a prefix of the type of the object that will be running within it.
        Parameters:
        type - this is the type of object to be executed
        thread - this is the thread containing the original name
        Returns:
        this will return the new name of the thread
      • createThread

        private java.lang.Thread createThread​(java.lang.Runnable task)
        This is used to create the thread that will be used to execute the provided task. The created thread will be renamed after it has been created and before it has been started.
        Parameters:
        task - this is the task that is to be executed
        Returns:
        this returns a thread to execute the given task