Class LoggingThreadFactory

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

    public class LoggingThreadFactory
    extends java.lang.Object
    implements java.util.concurrent.ThreadFactory
    Thread factory that logs uncaught exceptions thrown by the created threads.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean daemon
      Indicates if threads should be created as daemons.
      private java.util.logging.Logger logger
      The associated logger.
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingThreadFactory​(java.util.logging.Logger logger)
      Constructor.
      LoggingThreadFactory​(java.util.logging.Logger logger, boolean daemon)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Thread newThread​(java.lang.Runnable r)
      Creates a new thread.
      • Methods inherited from class java.lang.Object

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

      • logger

        private final java.util.logging.Logger logger
        The associated logger.
      • daemon

        private final boolean daemon
        Indicates if threads should be created as daemons.
    • Constructor Detail

      • LoggingThreadFactory

        public LoggingThreadFactory​(java.util.logging.Logger logger)
        Constructor.
        Parameters:
        logger - The associated logger.
      • LoggingThreadFactory

        public LoggingThreadFactory​(java.util.logging.Logger logger,
                                    boolean daemon)
        Constructor.
        Parameters:
        logger - The associated logger.
        daemon - Indicates if threads should be created as daemons.
    • Method Detail

      • newThread

        public java.lang.Thread newThread​(java.lang.Runnable r)
        Creates a new thread.
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory
        Parameters:
        r - The runnable task.