You can get the advantage of Pooled connections only if you maintain the client
for longer time. Now for your use case where HttpClient is Singleton:
1. If there is no requirement to update number of connections, idle connection
timeout or any settings related to pooled connections than there is no need to
instantiate Httpcient again and Singleton Httpclient will work. For settings
like connectiontimeout, sockettimeout - you can configure it at request level.
Also if there is no connection leaks than Singleton Httpclient can run fore
ever.
2. If there is a frequent requirement where number of connections needs to be
udpated than one solution can be - Have a watcher which detect change in
properties or config and watcher will instantiate another HttpClient and flips
it (atomically) with existing HttpClient. For any new connection request - new
HttpClient will serve the request. You can keep the old httpclient for x time
(to allow all previous request to complete) and than close all the connections.
Watcher instead of waiting for config change can periodically (once every hour)
can trigger above flips.
I would love to hear other possible solutions and designs.
Thanks,Jaikit
On Monday, May 18, 2015 8:00 PM, Mahendran Pirinthapan
<[email protected]> wrote:
Hi all,
In one of our project we are using httpclient-4.1.1 (we have to stick with
this version for some reason) to send requests to a remote server. We are
having a long running production environment for this project and we can
not restart the server frequently.
Currently we are using the httpclient in singleton manner. That is, we are
using the same httpclient instance to handle all the request using
ThreadSafeClientConnManager. In our production environment there can be
hundreds of request parallel.
Now I would like to know what would be the recommended way to use the
httpclient. Using in singleton manner? or Creating new httpclient instance
for each request?
Kindly appreciate your recommendations.
Thanks & Regards,
M.Pirinthapan
<https://plus.google.com/u/0/+MahendranPirinthapan/about>
<http://lk.linkedin.com/in/pirinthapan>
<https://www.facebook.com/MahendranPrinthapan/about>