title: How to tell if there is an available thread in a thread pool in java
body: <p>I am trying to proccess a queue of tasks from a database table as fast as possible while also limiting the number of threads to process the tasks.<br>
  I am using a fixed sized thread pool with <strong>Executors.newFixedThreadPool(N);</strong>  </p>
  
  <p>I want to know if there is a way of knowing if the thread pool is full, by that I mean are there currently 50 threads running, if so then I'll wait for a thread to be available before starting a new one instead of sleeping the main thread.</p>
  
  <p>Code of what I would like to do:</p>
  
  <pre><code>ExecutorService executor = Executors.newFixedThreadPool(N);
  ResultSet results;
  
  while( true ) {
      results = getWaitingTasksStmt.executeQuery();
  
      while( results.next() &amp;&amp; executor.notFull() ) {
          executor.submit( new thread( new runnableInheritedClass(results) ) );
      }
  }
  </code></pre>