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: releaseConnection() vs getConnectionManager().shutdown()
Date Thu, 29 Nov 2012 14:08:13 GMT
On Thu, 2012-11-29 at 13:56 +0000, Flavio Oliveira wrote:
> Oleg,
> 
> Definitely, thank you for clarifying.
> 
> By the way, I am going to do http get in different services (at same host or not). 
> So as I only have one instance of the HTTP Client, can I have different 
> threads with different timeout values sharing the same httpClient 
> instance without any side effect? 
> 
>                 HttpParams params = httpClient.getParams();
>                 HttpConnectionParams.setConnectionTimeout(params, timeout);
>                 HttpConnectionParams.setSoTimeout(params, timeout);
>                 HttpResponse response = httpClient.execute(httpget, context);
> 
> Regards, Flavio
> 

Flavio

You certainly can. Just make sure to use HttpParams associated with the
request and not with the client. Treat HttpParams on the client level as
global defaults which can be overridden selectively on the request
level.

Hope this helps

Oleg  

> > Subject: Re: releaseConnection() vs getConnectionManager().shutdown()
> > From: olegk@apache.org
> > To: httpclient-users@hc.apache.org
> > Date: Thu, 29 Nov 2012 14:29:48 +0100
> > 
> > On Wed, 2012-11-28 at 15:16 +0000, Flavio Oliveira wrote:
> > > Hi,
> > > 
> > > I use an instance of HttpClient to execute multiple methods from multiple threads.
> > > 
> > >         cm = new PoolingClientConnectionManager();
> > >         cm.setMaxTotal(20);
> > >         httpclient = new DefaultHttpClient(cm);
> > > 
> > > I release the connection by calling releaseConnection() on the method after
the response body has been read.                
> > > 
> > >          // Release connection
> > >          EntityUtils.consume(entity);
> > >          httpget.releaseConnection();
> > >          
> > > As I am using the PoolingClientConnectionManager I am not sure if I still need
to call "httpclient.getConnectionManager().shutdown()"
> > > because I released the connection by calling releaseConnection(). Could someone
clarify that?
> > > 
> > > Regards, Flavio 		 	   		  
> > 
> > Flavio,
> > 
> > The #shutdown() method needs to be called once you are completely done
> > with using the connection manager and would like to have all the
> > connections kept alive in the pool shut down immediately and all
> > resources associated with them released. Basically you need to do it
> > only once it the HttpClient life cycle, upon termination.
> > 
> > Hope this helps
> > 
> > Oleg
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > 
>  		 	   		  



---------------------------------------------------------------------
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