Thanks. Couple of questions. What do I expect to see when I turn on
the context logging? How do I determine if those connections are being
re-used?
Also, I am using log4j.xml and not log4j.properties, is there a place
that gives some example of configuring log4j.xml. If not then I'll
search log4j manuals.
Thanks again
On Mon, Oct 13, 2008 at 2:40 PM, Oleg Kalnichevski <[EMAIL PROTECTED]> wrote:
> On Mon, 2008-10-13 at 10:43 -0700, Mohit Anchlia wrote:
>> I saw quite a few posts on how to get rid of CLOSE_WAIT. And based on
>> those posts I changed my code but still I see CLOSE_WAITS. Below is my
>> test code:
>>
>>
>> public class Test {
>> private static MultiThreadedHttpConnectionManager con = new
>> MultiThreadedHttpConnectionManager();
>> private static void doGet(HttpClient client) {
>> System.out.println("CONN POOL " + con.getConnectionsInPool());
>> //System.out.println("DEF CON "
>> +client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
>> //System.out.println("MAX CON " +
>> client.getHttpConnectionManager().getParams().getMaxTotalConnections()
>> );
>>
>> GetMethod get = new GetMethod("http://localhost:8080/s/e");
>> get.setQueryString("version=V07.08&request_type=1");
>> get.addRequestHeader( "Connection", "close");
>> try {
>> long statusCode = client.executeMethod(get);
>>
>> System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
>> if (statusCode != HttpStatus.SC_OK) {
>> }
>> Thread.sleep(1000);
>> } catch(IOException ioe){
>> ioe.printStackTrace();
>> }catch (Exception e){} finally {
>> if (get != null) get.releaseConnection();
>> }
>> }
>> public static void main(String []a) throws Exception{
>>
>> HttpConnectionManagerParams params = new
>> HttpConnectionManagerParams();
>> params.setDefaultMaxConnectionsPerHost(2);
>> //params.setMaxConnectionsPerHost(2);
>> params.setMaxTotalConnections(2);
>> con.setParams(params);
>>
>> HttpClient client = new HttpClient();
>> client.getParams().setParameter("http.connection.timeout", new
>> Integer(1000));
>> int i = 0;
>> while ( i++ < 500){
>> client = new HttpClient(con);
>> doGet(client);
>> client = null;
>> con.closeIdleConnections(1000l);
>> //con.deleteClosedConnections();
>> }
>> /////////////
>>
>> so I am closing connection after each call, but still I see lot of
>> CLOSE_WAIT. Is there something that I am doing incorrectly? I was
>> expecting that above code will get rid of CLOSE_WAIT
>>
>
> Firstly, turn context logging on and see if HttpClient is reusing
> connections
>
> http://hc.apache.org/httpclient-3.x/logging.html
>
> Secondly, neither Thread#sleep() nor #closeIdleConnections() can
> guarantee exact timing. If you want all idle connections closed
> immediately you should pass 0 as a parameter to
> #closeIdleConnections();
>
> con.closeIdleConnections(0L);
>
> Hope this helps
>
> Oleg
>
>> ---------------------------------------------------------------------
>> 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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]