Om,

Nice set of questions. Looks almost like a FAQ :)

1. When I do "httpclient = new HttpClient", the object is created by default
with the SimpleHttpConnectionManager.

Correct.


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.

Yes, that's pretty much it. Just to clarify SimpleHttpConnectionManager contains a single instance of an HttpConnection and reuses it when possible. For example if you were to do two GETs from "http://jakarta.apache.org/"; then the connection would be reused. This assumes that the server supports connection persistence.


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)?

It depends on the server and a few other variables (like SSL and JVM version). In general HTTP 1.1 defaults to keep-alive and 1.0 defaults to close. These defaults can be overriden by the server using the connection header.


5. Is post.recycle() related to connection in any way? What is the purpose
of this? Is PostMethod ctor an expensive operation?

It calls releaseConnection() plus some other things. In general I do not use recycle much. I prefer to create a new instance as it's not particularly expensive.


6. SimpleHttpConnectionManager doc says "This manager makes no attempt to
provide exclusive access to the contained HttpConnection". Does this mean
that calling httpclient.execute() method in this case is not thread-safe?

Correct. Not thread safe. It would fail quite quickly if used from multiple threads.


7. If I wanted to use "connection pooling" should I be using
MultiThreadedHttpConnectionManager instead?  Or do I need to implement my
own pooling?

MultiThreadedHttpConnectionManager is what you want.


Mike


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to