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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to