title: Create a simple queue with Java threads
body: <p>I'm trying to create a simple queue with Java Thread that would allow a loop, say a for loop with 10 iterations, to iterate n (&lt; 10) threads at a time and wait until those threads are finished before continuing to iterate.</p>
  
  <p>Here's a better way to illustrate my problem:</p>
  
  <pre><code>for (int i = 1; i &lt;= 10; i++) {
      new Thread ( do_some_work() );
  
      if ( no_available_threads ) {
          wait_until_available_threads();
      }
  }
  
  do_some_work() {
      // do something that takes a long time
  }
  </code></pre>
  
  <p>Basically what I want to do is a copy of this: <a href="https://stackoverflow.com/questions/6558828/thread-and-queue/6558913#7034784">Thread and Queue</a></p>
  
  <p>How can I achieve this the most painless way?</p>