You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Igor Lubashev <Ig...@everypoint.com> on 2006/08/15 23:47:26 UTC
Managing connections
Hi!
I am new to this list, so I apologize if this topic has been beaten to
death already.
I am reading the tutorial, and it claims that I always must fully read
the body of the response (of the GET method, for example) before
releasing the connection.
What should I do if I really do not care about the response body (either
because of the status code or because I suspect that the server is a
rouge server and is sending me an infinite-sided body)? If there a way
to cleanly either abort the current method or cleanly kill the
connection (and let the MultiThreadedHttpConnectionManager open another
one next time it is needed)?
Thanks,
- Igor
RE: Managing connections
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-08-15 at 15:13 -0700, Igor Lubashev wrote:
> Great!
>
> Since the docs are rather sparse on this topic, do I need to call
> releaseConnection() after abort()?
One must _always_ call HttpMethod#releaseConnection in order to make
sure that the underlying connection gets returned to the pool.
> Also, are abort() and/or
> releaseConnection() idempotent?
>
One may safely invoke HttpMethod#abort and HttpMethod#releaseConnection
methods multiple times. One may not however call HttpMethod#abort once
HttpMethod#releaseConnection has been called.
> While we are at it, I am planning to use the httpclient in my app by
> getting the body as a stream and then reading data from that stream in
> chunks, each chunk in a possibly different thread. That is, only one
> thread will access the stream at a time, but the next time the stream is
> accessed, it could be accessed from a different thread. Is this safe?
> Or does httpclient use some ThreadLocal storage somewhere?
>
HttpClient does not use ThreadLocal-s. However, you have to provide
proper synchronization when accessing HttpMethod instances from multiple
threads. HttpMethod#abort is the only method of HttpMethod which is
thread-safe.
Oleg
> Many thanks,
>
> - Igor
>
>
> On Tue, 2006-08-15 at 14:47 -0700, Igor Lubashev wrote:
> > Hi!
> >
> > I am new to this list, so I apologize if this topic has been beaten to
> > death already.
> >
> > I am reading the tutorial, and it claims that I always must fully read
> > the body of the response (of the GET method, for example) before
> > releasing the connection.
> >
> >
> >
> > What should I do if I really do not care about the response body
> (either
> > because of the status code or because I suspect that the server is a
> > rouge server and is sending me an infinite-sided body)? If there a
> way
> > to cleanly either abort the current method or cleanly kill the
> > connection (and let the MultiThreadedHttpConnectionManager open
> another
> > one next time it is needed)?
>
> HttpMethod#abort is your friend
>
> Hope this helps
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Managing connections
Posted by Igor Lubashev <Ig...@everypoint.com>.
Great!
Since the docs are rather sparse on this topic, do I need to call
releaseConnection() after abort()? Also, are abort() and/or
releaseConnection() idempotent?
While we are at it, I am planning to use the httpclient in my app by
getting the body as a stream and then reading data from that stream in
chunks, each chunk in a possibly different thread. That is, only one
thread will access the stream at a time, but the next time the stream is
accessed, it could be accessed from a different thread. Is this safe?
Or does httpclient use some ThreadLocal storage somewhere?
Many thanks,
- Igor
On Tue, 2006-08-15 at 14:47 -0700, Igor Lubashev wrote:
> Hi!
>
> I am new to this list, so I apologize if this topic has been beaten to
> death already.
>
> I am reading the tutorial, and it claims that I always must fully read
> the body of the response (of the GET method, for example) before
> releasing the connection.
>
>
>
> What should I do if I really do not care about the response body
(either
> because of the status code or because I suspect that the server is a
> rouge server and is sending me an infinite-sided body)? If there a
way
> to cleanly either abort the current method or cleanly kill the
> connection (and let the MultiThreadedHttpConnectionManager open
another
> one next time it is needed)?
HttpMethod#abort is your friend
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Managing connections
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-08-15 at 14:47 -0700, Igor Lubashev wrote:
> Hi!
>
>
>
> I am new to this list, so I apologize if this topic has been beaten to
> death already.
>
>
>
> I am reading the tutorial, and it claims that I always must fully read
> the body of the response (of the GET method, for example) before
> releasing the connection.
>
>
>
> What should I do if I really do not care about the response body (either
> because of the status code or because I suspect that the server is a
> rouge server and is sending me an infinite-sided body)? If there a way
> to cleanly either abort the current method or cleanly kill the
> connection (and let the MultiThreadedHttpConnectionManager open another
> one next time it is needed)?
>
>
HttpMethod#abort is your friend
Hope this helps
Oleg
>
> Thanks,
>
>
>
> - Igor
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: Managing connections
Posted by Igor Lubashev <Ig...@everypoint.com>.
Thanks, Ronald!
Yes, I was basically asking for the functionality like abort(). I do
not mind writing an extra
"get.getResponseBodyAsStream().skip(Long.MAX_VALUE);" even if
get.releaseConnection() did not do it for me. I was concerned with
downloading tons of useless data from the network.
Thanks,
- Igor
-----Original Message-----
From: Roland Weber [mailto:ROLWEBER@de.ibm.com]
Sent: Wednesday, August 16, 2006 1:34 AM
To: HttpClient User Discussion
Subject: Re: Managing connections
Hello Igor,
> I am reading the tutorial, and it claims that I always must fully read
> the body of the response (of the GET method, for example) before
> releasing the connection.
This is not correct. You do not need to read the full body before
calling releaseConnection, because releaseConnection will read the
rest of it. If you are receiving short pages, just release the
connection and you will still have connection keep-alive. Only if
you are receiving huge pages which you don't want to be consumed
by releaseConnection, you have to call abort().
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: Managing connections
Posted by Roland Weber <RO...@de.ibm.com>.
Hello Igor,
> I am reading the tutorial, and it claims that I always must fully read
> the body of the response (of the GET method, for example) before
> releasing the connection.
This is not correct. You do not need to read the full body before
calling releaseConnection, because releaseConnection will read the
rest of it. If you are receiving short pages, just release the
connection and you will still have connection keep-alive. Only if
you are receiving huge pages which you don't want to be consumed
by releaseConnection, you have to call abort().
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org