hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCORE-12) "finally" bug in samples
Date Fri, 08 Sep 2006 10:06:23 GMT
    [ http://issues.apache.org/jira/browse/HTTPCORE-12?page=comments#action_12433372 ] 
            
Oleg Kalnichevski commented on HTTPCORE-12:
-------------------------------------------

> I think what you expect is:
> Test 1
> First close
> Test 2
> Connection kept alive... 

Not at all. I would expect the former.  

Please note the requests are executed in a _loop_. The connection is kept alive while in the
loop and is closed in the finally closed when the loop terminates. This is the expected behavior.

try {
  for (int i = 0; i < targets.length; i++) {
    if (!conn.isOpen()) {
      conn.open(params);
     }
     ...
     // execute a requesr
     ...
     if (!connStrategy.keepAlive(response, context)) {
       conn.close();
     } else {
        System.out.println("Connection kept alive...");
     }
     System.out.println("Looping. Not done yet");
  }
  System.out.println("Exiting loop. We are done");
} finally {
  System.out.println("And finally closing the damn thing");
  conn.close();
}


Feel free to make changes you deem necessary and provide a patch. Maybe that way I'll see
what you think is wrong with the sample code. 

Oleg

> "finally" bug in samples
> ------------------------
>
>                 Key: HTTPCORE-12
>                 URL: http://issues.apache.org/jira/browse/HTTPCORE-12
>             Project: HttpComponents Core
>          Issue Type: Bug
>          Components: Examples
>         Environment: All
>            Reporter: Gabriel Klein
>
> In code
> http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
> and
> http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
> You have
>       {
>           .....
>                 if (!connStrategy.keepAlive(response, context)) {
>                     conn.close();
>                 } else {
>                     System.out.println("Connection kept alive...");
>                 }
>             }
>         } finally {
>             conn.close();
>         }   
> The problem is that "conn.close();" is called everytime... even if you "System.out.println("Connection
kept alive...");".

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message