title: Java Thread Pool Executor Monitoring
body: <p>The ThreadPoolExecutor class in the Java SE 6 docs has the following <a href="http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html#getActiveCount%28%29" rel="nofollow noreferrer">method</a>:</p>
  
  <blockquote>
    <p><code>public int getActiveCount()</code></p>
    
    <p>Returns the approximate number of threads
    that are actively executing tasks.</p>
  </blockquote>
  
  <p>What is the meaning of <em>approximate</em> and <em>actively executing</em> here? </p>
  
  <p>Is there any guarantee that, if before, during and after the call to <code>getActiveCount()</code></p>
  
  <ol>
  <li><em>N</em> threads have been allotted from the pool for task execution, and</li>
  <li>None of these <em>N</em> threads are available for further task assignment,</li>
  </ol>
  
  <p>the integer returned by <code>getActiveCount()</code> will be exactly <em>N</em>?</p>
  
  <p>If <code>getActiveCount()</code> does not provide this guarantee, is there any other way to obtain this information in a more precise manner?</p>
  
  <p><strong>Prior SO Questions:</strong></p>
  
  <p>I have looked at <a href="https://stackoverflow.com/q/8198584/191776">Thread Pool Executor Monitoring Requirement</a> and <a href="https://stackoverflow.com/q/2657971/191776">How to tell if there is an available thread in a thread pool in java</a>, but they do not answer my queries.</p>