title: Java executors: how to be notified, without blocking, when a task completes?
body: <p>Say I have a queue full of tasks which I need to submit to an executor service.  I want them processed one at a time.  The simplest way I can think of is to:</p>
  
  <ol>
  <li>Take a task from the queue</li>
  <li>Submit it to the executor</li>
  <li>Call .get on the returned Future and block until a result is available</li>
  <li>Take another task from the queue...</li>
  </ol>
  
  <p>However, I am trying to avoid blocking completely.  If I have 10,000 such queues, which need their tasks processed one at a time, I'll run out of stack space because most of them will be holding on to blocked threads.  </p>
  
  <p>What I would like is to submit a task and provide a call-back which is called when the task is complete.  I'll use that call-back notification as a flag to send the next task. (functionaljava and jetlang apparently use such non-blocking algorithms, but I can't understand their code)</p>
  
  <p>How can I do that using JDK's java.util.concurrent, short of writing my own executor service?</p>
  
  <p>(the queue which feeds me these tasks may itself block, but that is an issue to be tackled later)</p>