Monday, 30 September 2013

Polling over a large number of IO connections in Java

Polling over a large number of IO connections in Java

Basically my problem is this : i have a server answering on a port to a
(large) number of requests and each of those requests translates into 1 or
more parallel calls to other services on other machines. Doing a thread
per request would not be efficient in this case so i'm trying to come with
a way to implement it in a async way. My solution so far consists of
basically keeping all the future objects that represent the connections to
the outside services in a array and continuously looping over it in a
dedicated thread, adding the finished ones to a BlockingQueue for further
processing. Is this efficient?
Is there a better way of doing this? The array is made of future objects
basically because the handler used to call the outside services will do
it's own share of async stuff beneath the hood so i can rely on the future
returning interface to take care of that IO efficiently.
Thanks in advance

No comments:

Post a Comment