You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by David Thielen <da...@windward.net> on 2016/12/31 19:53:40 UTC

Is HttpClient thread safe?

I am using the Apache HttpClient to read files from a website. When we do multiple requests at once, it appears that it will not read any more from the earlier CloseableHttpResponse.getEntity() streams. No error or anything, but it truncates the file.

Is this expected? And if so, is there a library out there that is thread safe? Should I go back to Url.getContent() and Authenticator.setDefault()?

thanks - dave


Re: Is HttpClient thread safe?

Posted by Bernd Eckenfels <ec...@zusammenkunft.net>.
Hello,
You can and should share the ahttpClient among multiple request threads. This way it can do pooling, keep alive and resource management. However do not concurrently use connections and basically stick to one thread for a complete execution. HttpResponse and Entity should be processed non-concurrent (for the blocking client)
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e405
GrussBernd-- 
http://bernd.eckenfels.net




On Sat, Dec 31, 2016 at 8:54 PM +0100, "David Thielen" <da...@windward.net> wrote:










I am using the Apache HttpClient to read files from a website. When we do multiple requests at once, it appears that it will not read any more from the earlier CloseableHttpResponse.getEntity() streams. No error or anything, but it truncates the file.

Is this expected? And if so, is there a library out there that is thread safe? Should I go back to Url.getContent() and Authenticator.setDefault()?

thanks - dave