title: An Actor "queue"?
body: <p>In Java, to write a library that makes requests to a server, I usually implement some sort of dispatcher (not unlike the one found here in the Twitter4J library: <a href="http://github.com/yusuke/twitter4j/blob/master/twitter4j-core/src/main/java/twitter4j/internal/async/DispatcherImpl.java" rel="nofollow noreferrer">http://github.com/yusuke/twitter4j/blob/master/twitter4j-core/src/main/java/twitter4j/internal/async/DispatcherImpl.java</a>) to limit the number of connections, to perform asynchronous tasks, etc.</p>
  
  <p>The idea is that N number of threads are created.  A "Task" is queued and all threads are notified, and one of the threads, when it's ready, will pop an item from the queue, do the work, and then return to a waiting state.  If all the threads are busy working on a Task, then the Task is just queued, and the next available thread will take it.</p>
  
  <p>This keeps the max number of connections to N, and allows at most N Tasks to be operating at the same time.</p>
  
  <p>I'm wondering what kind of system I can create with Actors that will accomplish the same thing?  Is there a way to have N number of Actors, and when a new message is ready, pass it off to an Actor to handle it - and if all Actors are busy, just queue the message?</p>