Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 74524 invoked from network); 10 Sep 2010 01:40:29 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Sep 2010 01:40:29 -0000 Received: (qmail 61853 invoked by uid 500); 10 Sep 2010 01:40:28 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 61800 invoked by uid 500); 10 Sep 2010 01:40:28 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 61792 invoked by uid 99); 10 Sep 2010 01:40:27 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Sep 2010 01:40:27 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [128.149.139.105] (HELO mail.jpl.nasa.gov) (128.149.139.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Sep 2010 01:40:03 +0000 Received: from mail.jpl.nasa.gov (altvirehtstap01.jpl.nasa.gov [128.149.137.72]) by smtp.jpl.nasa.gov (Switch-3.4.3/Switch-3.4.3) with ESMTP id o8A1ddQt009119 (using TLSv1/SSLv3 with cipher RC4-MD5 (128 bits) verified FAIL) for ; Thu, 9 Sep 2010 18:39:40 -0700 Received: from ALTPHYEMBEVSP30.RES.AD.JPL ([172.16.0.31]) by ALTVIREHTSTAP01.RES.AD.JPL ([128.149.137.72]) with mapi; Thu, 9 Sep 2010 18:39:40 -0700 From: "Huang, Thomas (388J)" To: "httpclient-users@hc.apache.org" Date: Thu, 9 Sep 2010 18:39:39 -0700 Subject: TIME_WAIT in httpclient-4.0.2 Thread-Topic: TIME_WAIT in httpclient-4.0.2 Thread-Index: ActQiQgzJaU95RVHQyO7Ubg8uQBKwQ== Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Source-IP: altvirehtstap01.jpl.nasa.gov [128.149.137.72] X-Source-Sender: Thomas.Huang@jpl.nasa.gov X-AUTH: Authorized X-Virus-Checked: Checked by ClamAV on apache.org Hi, I am new to HttpClient. I took the example directly from the HttpClient ja= vadoc by invoking it 10 times. The program ran fine, but I see 10 TIME_WAI= T. This suggests the example code is not closing the socket gracefully. I= s this a bug or am I looking at a bad example? The problem with TIME_WAIT = is the program will eventually hang if I increase the number of iterations.= Please advise. thanks, Thomas. import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import java.io.*; public class TimeWait { public static void test (String url) throws Exception { HttpClient httpclient =3D new DefaultHttpClient(); // Prepare a request object HttpGet httpget =3D new HttpGet(url); // Execute the request HttpResponse response =3D httpclient.execute(httpget); // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity =3D response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity !=3D null) { InputStream instream =3D entity.getContent(); try { BufferedReader reader =3D new BufferedReader( new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection and release it back to the connection manager. httpget.abort(); throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } } public static void main (String[] args) throws Exception { for (int i=3D0; i<10; ++i) { TimeWait.test("http://www.apache.org"); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org