Class CountingThreadFactory

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

    public class CountingThreadFactory
    extends java.lang.Object
    implements java.util.concurrent.ThreadFactory
    A custom ThreadFactory that maintains a count of how many threads this factory has created
    Author:
    Abhishek Sanoujam
    • Constructor Summary

      Constructors 
      Constructor Description
      CountingThreadFactory​(java.util.concurrent.ThreadFactory actualFactory)
      Constructor accepting the actual thread factory that will create the threads
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getNumberOfThreads()
      Returns the number of threads this factory has created and currently alive
      java.lang.Thread newThread​(java.lang.Runnable r)
      • Methods inherited from class java.lang.Object

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

      • CountingThreadFactory

        public CountingThreadFactory​(java.util.concurrent.ThreadFactory actualFactory)
        Constructor accepting the actual thread factory that will create the threads
        Parameters:
        actualFactory - the actual factory
    • Method Detail

      • newThread

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

        public int getNumberOfThreads()
        Returns the number of threads this factory has created and currently alive
        Returns:
        Returns the number of threads this factory has created and currently alive