On 10/18/07, Roland Weber <[EMAIL PROTECTED]> wrote:
>
> Puneet Lakhina wrote:
> >  public void run() {
> >
> >         HttpClient client = new HttpClient();
> >         PostMethod postMethod  = new PostMethod(sameURL);
> >         /*Set parameters in post method*/
> >         client.executeMethod();
> >          /*Do something with the response*/
> >         postMethod.releaseConnection();
> > }
>
> This will leak a connection for every request, until they
> are released by garbage collection.
>
> > I am a little confused as to how the connection management takes place.
> > Should i be using the same HttpClient object across different threads?
> > Should I be in that case using the MultiThreadedConnectionManager?
>
> Yes and yes. You are looking for the Threading Guide:
> http://jakarta.apache.org/httpcomponents/httpclient-3.x/threading.html


I hope I am interpreting it right. If i am making threads by implementing
Runnable, then the HttpClient instance should be a static variable,
something like the following.
public MyThreads implements Runnable{
private static HttpClient client = new HttpClient(new
MultiThreadedHttpConnectionManager());
public void run() {
try {
client.executeMethod(method);
}finally {
method.releaseConnection();
}
}
}

hope that helps,
>   Roland
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Puneet
http://sahyog.blogspot.com/

Reply via email to