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 Oleg Kalnichevski <ol...@apache.org> on 2005/01/27 00:06:43 UTC
Re: Cookies with multithreaded connection manager - [was Re: Any
equivalent to setReuseAddress() to true - ie reuse sockets in TIME_WAIT
state]
David,
Create a instance of HttpState per thread and pass it to
HttpClient#executeMethod as a parameter. This should do the trick
Oleg
On Wed, 2005-01-26 at 17:54 -0500, dhay@lexmark.com wrote:
> Hi,
>
> Thanks for the tip. I have tried this, but ran into a problem with cookies
> when using it.
>
> I created a single HttpClient instance, with a
> MultiThreadedHttpConnectionManager. I pass this client to each thread that
> I start.
>
> However, I also need to keep track of session information for each thread,
> and am not sure how to do that in this model (I get another connection from
> my caller, and hence another thread spawned, which must be part of the same
> session). I was just calling setState as follows if the thread was part of
> a particular session like this:
>
> if (_session != null)
> {
> // adding session cookie previously saved");
> HttpState initialState = new HttpState();
> initialState.addCookie(_session);
> _httpClient.setState(initialState);
> }
>
> This obviously doesn't work with multiple threads accessing the same
> HttpClient.
>
> What am I missing? Is there another way to do cookies?
>
> thanks,
>
> David
>
>
>
> |---------+---------------------------->
> | | Oleg Kalnichevski|
> | | <olegk@apache.org|
> | | > |
> | | |
> | | 01/24/2005 06:13 |
> | | PM |
> | | Please respond to|
> | | "HttpClient User |
> | | Discussion" |
> | | |
> |---------+---------------------------->
> >-----------------------------------------------------------------------------------------------------------------------|
> | |
> | To: HttpClient User Discussion <ht...@jakarta.apache.org> |
> | cc: |
> | Subject: Re: Any equivalent to setReuseAddress() to true - ie reuse sockets in TIME_WAIT state |
> >-----------------------------------------------------------------------------------------------------------------------|
>
>
>
>
> David,
>
> What kind of connection manager are you using? If yes, consider using
> the so called multithreaded connection manager that maintains a pool of
> connections:
>
> http://jakarta.apache.org/commons/httpclient/3.0/threading.html
>
> Hope this helps,
>
> Oleg
>
> On Mon, 2005-01-24 at 15:04 -0500, dhay@lexmark.com wrote:
> > Hi,
> >
> > I am creating alot of connections to Tomcat 5 using HttpClient. As a
> > result, I have a lot of sockets in the TIME_WAIT state, which lead to a
> > BindException - Connection In use.
> >
> > Is there any way to get the HttpClient to reuse these sockets akin to
> using
> > setReuseAddress(true) when using a plain socket?
> >
> > Any other suggestions?
> >
> > cheers,
> >
> > David
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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