title: ThreadPoolExecutor Block When Queue Is Full?
body: <p>I am trying to execute lots of tasks using a ThreadPoolExecutor. Below is a hypothetical example:</p>
  
  <pre><code>def workQueue = new ArrayBlockingQueue&lt;Runnable&gt;(3, false)
  def threadPoolExecutor = new ThreadPoolExecutor(3, 3, 1L, TimeUnit.HOURS, workQueue)
  for(int i = 0; i &lt; 100000; i++)
      threadPoolExecutor.execute(runnable)
  </code></pre>
  
  <p>The problem is that I quickly get a <code>java.util.concurrent.RejectedExecutionException</code> since the number of tasks exceeds the size of the work queue. However, the desired behavior I am looking for is to have the main thread block until there is room in the queue. What is the best way to accomplish this?</p>