hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Trying to understand if async-http-client is actually async and how it make use of thread.
Date Tue, 13 Jan 2015 11:21:53 GMT
On Tue, 2015-01-13 at 13:53 +0530, Bhuvan Gupta wrote:
> Hello all,
> 
> I was looking for async java http client.
> 
> I came across Apache asyncClient
> <https://hc.apache.org/httpcomponents-asyncclient-4.0.x/index.html> and
> went through the following examples
> <https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/examples/org/apache/http/examples/nio/client/AsyncClientHttpExchangeFutureCallback.java>
> .
> 
> so in example we register a callback object and completed(...) get called
> when the response of the request come back.
> 
> QUESTION:
> 
> Now internally does the ASyncClient
> 
> 1 <https://hc.apache.org/httpcomponents-asyncclient-4.0.x/index.html> make
> thread to wait per request or
> 
> 2
> <https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/examples/org/apache/http/examples/nio/client/AsyncClientHttpExchangeFutureCallback.java>
> it
> actually use the NIO and make one thread to poll the socket selectors and
> call the completed(...) method
> 

HttpAsyncClient uses so called I/O reactor pattern. For details see:

http://hc.apache.org/httpcomponents-core-4.4.x/tutorial/html/nio.html


> Now if [2] is true than if i block the thread under completed(...) call
> than
> 
> [1] how/will  AsyncClient be able to handle other responses.
> 

It will not. All connections managed by the same I/O dispatch thread
will end up blocked as well. 

> [2] is there any configuration around number of thread which will poll
> socket selectors
> 

The number of I/O dispatch threads used internally is equal to that of
CPU cores by default.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message