Responses follow....
Om Narayan wrote:
The connection will be reused if you invoke another request that uses the "Simple" connection manager.Please validate my understanding of how HttpClient and the other classes work together.
1. When I do "httpclient = new HttpClient", the object is created by default with the SimpleHttpConnectionManager. 2. I create "post = new PostMethod(url)" and call httpclient.executeMethod(post). At this point httpclient takes the url in the post object and using the SimpleHttpConnectionManager, creates a HttpConnection object. This connection is retained by the SimpleHttpConnectionManager and (possibly?) reused.
"releasing" a connection should not be confused with "closing" the connection. "Releasing" ensures that it can be safely reused by a subsequent request. For the most part, releasing a connection is entirely unnecessary with the "SimpleHttpConnectionManager", as it only has one connection, and it will "release" it internally before handing it out for a subsequent request. Closing a connection only happens when necessary - as in a "Connection: close" header, an Http 1.0 response, or any of the other various standard reasons for forcing a connection closed. As a general rule of thumb, HttpClient only closes the underlying socket connection when absolutely necessary (unless you are using HTTPS and a proxy server, as I recall).3. After connection is established, data is posted, and the result retrieved. 4. I do post.releaseConnection(). Does the connection get closed at this point? Is the HttpConnection object still around? What do I need to do if I had wanted to have the connection stay alive (because it takes time to re-establish the connection)?
5. Is post.recycle() related to connection in any way? What is the purposeI think that previous discussion on the "recycle" operation has indicated to me that this is a largely spurious function. It might be useful, but I suspect it is mostly premature optimization. The code in our application simply makes a new "Method" object for each new request. Of course, we don't make millions of requests, which others might be, and they might report differently.
of this? Is PostMethod ctor an expensive operation?
6. SimpleHttpConnectionManager doc says "This manager makes no attempt toAs soon as you do an "execute" on the next method using the SimpleHttpConnectionManager, the previous response data becomes invalid. In this sense, it is not even "single thread" safe. For example, code written like this: execute A, execute B, read A, read B will fail on the attempt to read A. Used across multiple threads, even worse things can happen. I recommend using MultiThreadedHttpConnectionManager.
provide exclusive access to the contained HttpConnection". Does this mean
that calling httpclient.execute() method in this case is not thread-safe?
It should be sufficient to use the MultiThreadedHttpConnectionManager, which actually serves multiple tasks, one of them being pooling.7. If I wanted to use "connection pooling" should I be using MultiThreadedHttpConnectionManager instead? Or do I need to implement my own pooling?
Good luck.
I am sure I have other questions, but this will do for now. :) Thanks.
Om.
-Eric Johnson
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
