Massimo, Calling HttpMethod#releaseConnection() does not guarantee that the active connection will be closed. HttpClient _always_ tries its best to reuse open connections. Whenever a connection can be kept alive, HttpClient will keep it alive. That effectively means that when an HttpClient instance goes out of scope, the underlying connection (or several connections) may be left open until GC-ed.
Therefore, we recommend to have only one HttpClient instance per application/component. New HttpClient instance per request approach is HIGHLY discouraged: class MyCommunicationComponent { private HttpClient agent = new HttpClient(); private void doStuff() { HttpMethod method = new GetMethod(timerURL); this.agent.executeMethod(method); ... } } If you absolutely have to create new instances of HttpClient we recommend explicitly shutting down the connection manager, whenever you are done using an HttpClient instance: class MyCommunicationComponent { private void doStuff() { MultiThreadedHttpConnectionManager connman = new MultiThreadedHttpConnectionManager(); HttpClient agent = new HttpClient(connman); HttpMethod method = new GetMethod(timerURL); agent.executeMethod(method); ... connman.shutdown(); } } Hope this helps Oleg On Thu, 2004-10-21 at 15:34, Massimo Signori wrote: > Hi everybody, this is my code: > > private void notifyTimeServer() { > // > logger.debug("notifyTimeServer, " + timerURL); > // > HttpClient client = new HttpClient(); > HttpMethod method = new GetMethod(timerURL); > int statusCode = -1; > for (int attempt = 0; statusCode == -1 && attempt < > MAX_CALLING_ATTEMPTS; attempt++) { > // > logger.debug("Establishing connection"); > // > try { > statusCode = client.executeMethod(method); > } > catch (Exception e) { > // > logger.error("Error calling jsp"); > // > } > } > if (statusCode != -1) { > // > logger.debug("Connection estabilished"); > // > byte[] responseBody = method.getResponseBody(); > method.releaseConnection(); > } > } > > I was looking with TCPView the number of TCP connections that this piece of > code is opening when talking to the server and I saw that opens an > incredible number of connections. All TCP connections are in TIME_WAIT > state. > Is there something wrong in this code? Or I'm forgetting something? > > Best regards, > > Massimo > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]