hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: Questions related to the use of HttpClient classes
Date Thu, 05 Jun 2003 22:25:34 GMT
Quite so.  I will get one started.  Any other questions you would like 
to see added?

Mike

On Thursday, June 5, 2003, at 04:59 PM, Oleg Kalnichevski wrote:

> Mike,
>
> Why do not we indeed make a FAQ document out of this Q & A session 
> with?
>
> Oleg
>
> On Thu, 2003-06-05 at 22:18, Michael Becke wrote:
>> 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: 
>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: 
>> commons-httpclient-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


Mime
View raw message