You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2005/11/03 14:52:21 UTC

Re: idle connections thread

On Thu, Nov 03, 2005 at 11:05:13AM +0000, Teja Sai Krishna wrote:
>  Hi 
>  
> 
> We are calling IdleConnectionTimeoutThread() method to close the idle connections. But this looks like it not calling as we expected. 
> 
>  
> 
> We have set the setTimeoutInterval as 5000.  We are creating client object for each request. 
> 
>  
> 
> Do we need to implement Connection Manager and maintain connection pool and get the Connection Manager to close the Idle connections?
> 
>  
> 
> Can we call IdleConnectionTimeoutThread for each request like this?
> 
>

You can, but it makes no sense of what so ever

Oleg

> 
>  
> 
> My Client code looks like following
> 
> ==============================================
> 
>  
> 
> public String connect (String reqMsg) throws Exception {
> 
>  
> 
>             PostMethod method = new PostMethod(url.toExternalForm());
> 
>             HttpClient client = new HttpClient();
> 
>             
> 
>             IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
> 
>             ict.addConnectionManager(client.getHttpConnectionManager());
> 
>             ict.setConnectionTimeout(5000);
> 
>             ict.start();
> 
>  
> 
> try {
> 
>                  method.setRequestBody(reqMsg);
> 
>                   int statusCode = client.executeMethod(method);
> 
>                   results = method.getResponseBodyAsString();
> 
>                    }
> 
>                             catch(ConnectException cex){
> 
>                                     System.out.println("Exception "+cex);
> 
>                             }catch(Exception e){
> 
>                                     System.out.println("Exception occured "+e);
> 
>             
> 
>                             }finally{
> 
>                                     method.releaseConnection();
> 
>                      
> 
>                             }
> 
> }           
> 
>  
> 
> ----------------------------------------
> 
>  
> 
> Thanks
> 
> Teja
> 
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 

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


Re: idle connections thread

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, Nov 03, 2005 at 03:30:39PM +0000, Teja Sai Krishna wrote:
> Hi,
>  
> Thanks for your rsponse.
>  
> Here we are creating HttpClient object for each request and not using any MultiThreadedHttpConnectionManager. In this case how can we implement IdleConnectionTimeoutThread? 
> 

No. Create only one instance of HttpClient and one instance of
IdleConnectionTimeoutThread, register the connection manager of that
HttpClient with the idle connection handler thread, and use the same
HttpClient to execute requests.

If you are not going to reuse the connection manager what's the whole
point of registering it the idle connection handler? 

Oleg


> Do we need to call addConnectionManage for each request? , Basically I am not getting how to implement this IdleConnectionTimeoutThread when we are not using nay connection Manager. 
>  
> Do we have any sample program in our tutorial?
>  
> Thanks
> Teja
> 
> 
> Oleg Kalnichevski <ol...@apache.org> wrote:
> On Thu, Nov 03, 2005 at 11:05:13AM +0000, Teja Sai Krishna wrote:
> > Hi 
> > 
> > 
> > We are calling IdleConnectionTimeoutThread() method to close the idle connections. But this looks like it not calling as we expected. 
> > 
> > 
> > 
> > We have set the setTimeoutInterval as 5000. We are creating client object for each request. 
> > 
> > 
> > 
> > Do we need to implement Connection Manager and maintain connection pool and get the Connection Manager to close the Idle connections?
> > 
> > 
> > 
> > Can we call IdleConnectionTimeoutThread for each request like this?
> > 
> >
> 
> You can, but it makes no sense of what so ever
> 
> Oleg
> 
> > 
> > 
> > 
> > My Client code looks like following
> > 
> > ==============================================
> > 
> > 
> > 
> > public String connect (String reqMsg) throws Exception {
> > 
> > 
> > 
> > PostMethod method = new PostMethod(url.toExternalForm());
> > 
> > HttpClient client = new HttpClient();
> > 
> > 
> > 
> > IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
> > 
> > ict.addConnectionManager(client.getHttpConnectionManager());
> > 
> > ict.setConnectionTimeout(5000);
> > 
> > ict.start();
> > 
> > 
> > 
> > try {
> > 
> > method.setRequestBody(reqMsg);
> > 
> > int statusCode = client.executeMethod(method);
> > 
> > results = method.getResponseBodyAsString();
> > 
> > }
> > 
> > catch(ConnectException cex){
> > 
> > System.out.println("Exception "+cex);
> > 
> > }catch(Exception e){
> > 
> > System.out.println("Exception occured "+e);
> > 
> > 
> > 
> > }finally{
> > 
> > method.releaseConnection();
> > 
> > 
> > 
> > }
> > 
> > } 
> > 
> > 
> > 
> > ----------------------------------------
> > 
> > 
> > 
> > Thanks
> > 
> > Teja
> > 
> > 
> > Send instant messages to your online friends http://uk.messenger.yahoo.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 

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


Re: idle connections thread

Posted by Teja Sai Krishna <sa...@yahoo.com>.
Hi,
 
Thanks for your rsponse.
 
Here we are creating HttpClient object for each request and not using any MultiThreadedHttpConnectionManager. In this case how can we implement IdleConnectionTimeoutThread? 
 
Do we need to call addConnectionManage for each request? , Basically I am not getting how to implement this IdleConnectionTimeoutThread when we are not using nay connection Manager. 
 
Do we have any sample program in our tutorial?
 
Thanks
Teja


Oleg Kalnichevski <ol...@apache.org> wrote:
On Thu, Nov 03, 2005 at 11:05:13AM +0000, Teja Sai Krishna wrote:
> Hi 
> 
> 
> We are calling IdleConnectionTimeoutThread() method to close the idle connections. But this looks like it not calling as we expected. 
> 
> 
> 
> We have set the setTimeoutInterval as 5000. We are creating client object for each request. 
> 
> 
> 
> Do we need to implement Connection Manager and maintain connection pool and get the Connection Manager to close the Idle connections?
> 
> 
> 
> Can we call IdleConnectionTimeoutThread for each request like this?
> 
>

You can, but it makes no sense of what so ever

Oleg

> 
> 
> 
> My Client code looks like following
> 
> ==============================================
> 
> 
> 
> public String connect (String reqMsg) throws Exception {
> 
> 
> 
> PostMethod method = new PostMethod(url.toExternalForm());
> 
> HttpClient client = new HttpClient();
> 
> 
> 
> IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
> 
> ict.addConnectionManager(client.getHttpConnectionManager());
> 
> ict.setConnectionTimeout(5000);
> 
> ict.start();
> 
> 
> 
> try {
> 
> method.setRequestBody(reqMsg);
> 
> int statusCode = client.executeMethod(method);
> 
> results = method.getResponseBodyAsString();
> 
> }
> 
> catch(ConnectException cex){
> 
> System.out.println("Exception "+cex);
> 
> }catch(Exception e){
> 
> System.out.println("Exception occured "+e);
> 
> 
> 
> }finally{
> 
> method.releaseConnection();
> 
> 
> 
> }
> 
> } 
> 
> 
> 
> ----------------------------------------
> 
> 
> 
> Thanks
> 
> Teja
> 
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 

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


Send instant messages to your online friends http://uk.messenger.yahoo.com