In Java, to write a library that makes requests to the server, I usually implement a kind of dispatcher (as opposed to found in the Twitter4J library here: http://github.com/yusuke/twitter4j/blob/master/twitter4j-core/src /main/java/twitter4j/internal/async/DispatcherImpl.java ) to limit the number of connections, perform asynchronous tasks, etc.
The idea is that N threads are created. The "task" is placed in the queue, and all threads are notified, and one of the threads, when it is ready, will pull the item out of the queue, do the work and return to the standby state. If all threads are busy with work on a task, then the task is simply queued, and the next available thread will accept it.
This supports the maximum number of connections to N and allows you to simultaneously work no more than N tasks.
I am wondering which system I can create with Actors who will do the same thing? Is there a way to have N number of Actors, and when the new message is ready, send it to the Actor to process it - and if all the Actors are busy, just leave the message in the queue?
synic source
share