We have a method in our app that calls httpclient like this:
private HttpClient client = new HttpClient();
public String send(String urlString, String xml)
{
PostMethod postMethod = new PostMethod(urlString);
// Put the XML in the request
try
{
RequestEntity entity = new
StringRequestEntity(xml, "text/xml", "UTF-8");
postMethod.setRequestEntity(entity);
}
catch(UnsupportedEncodingException e1)
{
logger.warn("Couldn't encode the xml?", e1);
return "" +
IContentPublishingService.ACTION_ERROR;
}
// Send the data and get the response
String response = null;
try
{
client.executeMethod(postMethod);
byte[] responseBody =
postMethod.getResponseBody();
response = new String(responseBody);
}
catch(HttpException e)
{
logger.warn("Fatal protocol violation: " +
e.getMessage());
return "" +
IContentPublishingService.ACTION_ERROR;
}
catch(IOException e)
{
logger.warn("Fatal transport error: " +
e.getMessage());
return "" +
IContentPublishingService.ACTION_ERROR;
}
finally
{
// Release the connection.
postMethod.releaseConnection();
}
return response;
}
This method is called rapidly by a single thread in our application.
After 1500 calls or so, we start to see java.net.SocketException, too
many open files. Netstat reveals that there are many sockets in
CLOSE_WAIT and TIME_WAIT states. It seems that httpclient is not
reusing the connection managed by the HttpClient instance, and instead
is closing the connection and creating a new one. This appears to be in
conflict with all the documentation that we could find.
An interesting wrinkle is that the sending and receiving side of the
connection are both on the same machine. The URL is constructed using
the machine's dns name, not "localhost".
------------------------------------------------------------------------
--
Kenneth DeLong
Software Architect
Engineering
BabyCenter, LLC
[EMAIL PROTECTED]
p: 415.344.7616
AIM: kenwdelong
http://www.babycenter.com
This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies of
the original message. If you are the intended recipient, please be advised that
the content of this message is subject to access, review and disclosure by the
sender's Email System Administrator.