Class Adept2ThreadFactory

java.lang.Object
de.aristaflow.adept2.util.threading.Adept2ThreadFactory
All Implemented Interfaces:
Thread.UncaughtExceptionHandler, ThreadFactory

public class Adept2ThreadFactory extends Object implements ThreadFactory, Thread.UncaughtExceptionHandler
The default thread factory overwritten to name the threads. Executors.defaultThreadFactory()
  • Field Details

    • poolNumber

      protected static final AtomicInteger poolNumber
      The counter for the pools.
    • group

      protected final ThreadGroup group
      The group for the threads.
    • threadNumber

      protected final AtomicInteger threadNumber
      The counter for the threads.
    • namePrefix

      protected final String namePrefix
      The prefix of the thread name, naming the user of this thread factory.
    • stackSize

      protected final long stackSize
      The desired stack size (in Bytes) for any new thread in bytes of address space.
    • priority

      protected final int priority
      The priority for the created threads.
    • daemon

      protected final boolean daemon
      Whether to create daemon threads.
    • cleanup

      protected final Runnable cleanup
      The cleanup runnable injected into all created threads to be executed just before the thread terminates.
    • logger

      protected final Logger logger
      Logger for logging uncaught exceptions.
  • Constructor Details

    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, Logger logger)
      Creates a new thread factory with the designated name, a default stack size and a priority one less than normal.
      Parameters:
      name - The name of the pool, used to identify the thread
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, Runnable cleanup, Logger logger)
      Creates a new thread factory with the designated name, a default stack size and a priority one less than normal.
      Parameters:
      name - The name of the pool, used to identify the thread
      cleanup - A cleanup runnable injected into all created threads to be executed just before the thread terminates.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, boolean daemon, Logger logger)
      Creates a new thread factory with the designated name, a default stack size, a priority one less than normal.
      Parameters:
      name - The name of the pool, used to identify the thread
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
      daemon - Whether to create daemon threads.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, long stackSize, Logger logger)
      Creates a new thread factory with the designated parameters and a priority one less than normal and non-daemon threads.
      Parameters:
      name - The name of the pool, used to identify the thread
      stackSize - The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, int priority, Logger logger)
      Creates a new thread factory with the designated parameters and a default stack size for non-daemon threads.
      Parameters:
      name - The name of the pool, used to identify the thread
      priority - The priority of the created threads.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, long stackSize, int priority, Logger logger)
      Creates a new thread factory with the designated parameters for non-daemon threads.
      Parameters:
      name - The name of the pool, used to identify the thread
      stackSize - The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.
      priority - The priority of the created threads. If this is lower than Thread.MIN_PRIORITY, Thread.MIN_PRIORITY will be used, the same applies inversely to Thread.MAX_PRIORITY.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Logger logger)
      Creates a new thread factory with the designated parameters.
      Parameters:
      name - The name of the pool, used to identify the thread
      stackSize - The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.
      priority - The priority of the created threads. If this is lower than Thread.MIN_PRIORITY, Thread.MIN_PRIORITY will be used, the same applies inversely to Thread.MAX_PRIORITY.
      daemon - Whether to create daemon threads.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
    • Adept2ThreadFactory

      public Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Runnable cleanup, Logger logger)
      Creates a new thread factory with the designated parameters.
      Parameters:
      name - The name of the pool, used to identify the thread
      stackSize - The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.
      priority - The priority of the created threads. If this is lower than Thread.MIN_PRIORITY, Thread.MIN_PRIORITY will be used, the same applies inversely to Thread.MAX_PRIORITY.
      daemon - Whether to create daemon threads.
      cleanup - A cleanup runnable injected into all created threads to be executed just before the thread terminates.
      logger - The logger of the caller, to which uncaught exceptions are going to be logged.
  • Method Details

    • newThread

      public Thread newThread(Runnable r)
      Specified by:
      newThread in interface ThreadFactory
    • uncaughtException

      public void uncaughtException(Thread t, Throwable e)
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
    • getNamePrefix

      public String getNamePrefix()
      Gets the name prefix this factory uses for new threads.
      Returns:
      The name prefix this factory uses for new threads.
    • getLogger

      public Logger getLogger()
      Gets the logger this factory uses for uncaught exceptions.
      Returns:
      The logger this factory uses for uncaught exceptions.