hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ortwin Glück <ortwin.glu...@nose.ch>
Subject Re: threads problem with many connections
Date Fri, 01 Oct 2004 15:56:12 GMT


Guillaume Cottenceau wrote:
> Ok, thanks for this precise code excerpt.

Welcome...

> Is it considered safe to interrupt the execute task that way? 

Define 'safe'...

> Is
> method.releaseConnection() the way to go for full cleanup of
> underlying resources, or the interruption might leave things in a
> bad state?

Paranoid code:

import org.apache.commons.httpclient.util.TimeoutController;

Runnable task = new Runnable() {
    public void run() {
       try {
         client.execute(method);
       } finally {
         method.releaseConnection();
       }
    }
}
long timeout = ...; //millis
try {
   TimeoutController.execute(task, timeout);
} catch(TimeoutController.TimeoutException e) {
    /* task has been sent an interrupt signal by now */
}

That way the connection will be returned to an eventual connection pool. 
It's just not well defined when that will happen. You might want to use 
the SimpleConnectionManager instead and create a new HttpClient object 
for every request if you want to be really safe against resource leaks.

-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Mime
View raw message