Class DaemonThreadFactory

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

    public final class DaemonThreadFactory
    extends java.lang.Object
    implements java.util.concurrent.ThreadFactory
    A ThreadFactory that delegates to Executors.defaultThreadFactory() and marks all threads as daemon.

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicInteger counter  
      private java.util.concurrent.ThreadFactory delegate  
      private java.lang.String namePrefix  
      private boolean propagateContextForTesting  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Thread newThread​(java.lang.Runnable runnable)  
      • Methods inherited from class java.lang.Object

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

      • namePrefix

        private final java.lang.String namePrefix
      • counter

        private final java.util.concurrent.atomic.AtomicInteger counter
      • delegate

        private final java.util.concurrent.ThreadFactory delegate
      • propagateContextForTesting

        private final boolean propagateContextForTesting
    • Constructor Detail

      • DaemonThreadFactory

        public DaemonThreadFactory​(java.lang.String namePrefix)
      • DaemonThreadFactory

        public DaemonThreadFactory​(java.lang.String namePrefix,
                                   boolean propagateContextForTesting)
        DaemonThreadFactory's constructor.
        Parameters:
        namePrefix - Used when setting the new thread's name.
        propagateContextForTesting - For tests only. When enabled, the current thread's Context will be passed over to the new threads, this is useful for validating scenarios where context propagation is available through bytecode instrumentation.
    • Method Detail

      • newThread

        public java.lang.Thread newThread​(java.lang.Runnable runnable)
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory