hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marko Asplund <marko.aspl...@ixonos.com>
Subject ConnectionPoolTimeoutException with multi-threaded HttpClient usage
Date Thu, 13 Dec 2012 20:18:38 GMT

I'm having problems using HttpClient in a multi-threaded environment.
When HttpClient.execute is called I occasionally get the following
error, even when there
probably should be connections available in the pool.

org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting
for connection from pool
        at org.apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.java:232)
        at org.apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.java:199)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)

Should I explicitly release the connection after each HTTP request is executed?
Is there something else that should be done to clean up after each request?
The HC tutorial recommends passing a per-thread HttpContext object to
HC.execute but is this required?
What kind of state is actually stored in HttpContext?

Below is a simplified version of the code.

// one-time initialization
PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
HttpClient httpClient = new DefaultHttpClient(cm);

// executed repeatedly by multiple concurrent threads
HttpGet rq = new HttpGet(uri);
InputStream is = null;
try {
  HttpResponse res = httpClient.execute(rq);
  // ...
  is = res.getEntity().getContent();
} finally {

// one-time disposal



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

View raw message