hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joan Balaguero" <joan.balagu...@grupoventus.com>
Subject Releasing connections
Date Tue, 30 Mar 2010 14:29:53 GMT
Hello,

 

I’ve implemented the following code to send a request, read the response and
returns back the connection to the pool:

 

(…)

Try

{

 (…)

 entity  = this.objHttp.execute(objPost));

  

 if (entity != null)

 {

  bis                   = new BufferedInputStream(entity.getContent());

  ByteArrayOutputStream buffer = new
ByteArrayOutputStream(httpOutBufferSize);

  byte[] tmp            = new byte[httpOutBufferSize];

  int numBytesRead      = 0;

 

  while ((numBytesRead = bis.read(tmp)) >= 0) buffer.write(tmp, 0,
numBytesRead);

  bis.close();

  bis = null;

 }

}

Catch (Exception e) {  throw new ProxyServletException(); }

Finally

{

 If (bis != null)

 {

  Try { bis.close(); bis = null; } catch (Exception e1) {}

 }

 

 If (entity != null)

 {

  Try { entity.consumeContent(); } catch (Exception e1) {}

 }

}

 

With this code:

 

1.       The connection is returned back to the pool correctly (the pool
never becomes exhausted).

2.       But I have more and more instances of java.net.* classes in my heap
histogram:

 

For example:

SockSocketImpl (number of instances)

12:30     19.517

13:30     70.731

14:00   107.061

 

SocketInputStream

12:30           907

13:30     68.650

14:00   103.568

 

 

It seems that the connection is returned back to the pool but the resources
associated with the http response are not freed up. At 12:20 I started
Tomcat, and the load from 12:20 since now is similar.

 

Is there any error in my code that I’m not able to see?

 

Thanks in advance,

 

Joan.

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message