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 Mohit Anchlia <mo...@gmail.com> on 2008/10/13 19:45:42 UTC

Multiple calls to HttpClient

What happens when an instance of HttpClient instance is created for
each request? Does it internally get associated with one Connection
manager or there is new connection manager created for each HttpClient
instance?

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2008-10-13 at 15:26 -0700, Mohit Anchlia wrote:
> What's the default time that these managers use to close the connection?
> 

Indefinite. Users are encouraged to implement a custom eviction policy
that suits their specific application requirements.

Oleg


> On Mon, Oct 13, 2008 at 2:41 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Mon, 2008-10-13 at 10:45 -0700, Mohit Anchlia wrote:
> >> What happens when an instance of HttpClient instance is created for
> >> each request? Does it internally get associated with one Connection
> >> manager or there is new connection manager created for each HttpClient
> >> instance?
> >>
> >
> > New connection manager created for each HttpClient instance
> >
> > Oleg
> >
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
What's the default time that these managers use to close the connection?

On Mon, Oct 13, 2008 at 2:41 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Mon, 2008-10-13 at 10:45 -0700, Mohit Anchlia wrote:
>> What happens when an instance of HttpClient instance is created for
>> each request? Does it internally get associated with one Connection
>> manager or there is new connection manager created for each HttpClient
>> instance?
>>
>
> New connection manager created for each HttpClient instance
>
> Oleg
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-10-15 at 10:14 -0700, Mohit Anchlia wrote:
> I am trying to keep CLOSE_WAIT close to 0. I also noticed that apache
> libs threw error when I was using one instance of HttpClient accross
> threads, that's the reason I started using one Httpclient per thread
> and then releaseConnection, closeIdleConnection and deleteConnection
> after every invocation of doGet in below code.
> 

Just do con.closeIdleConnections(0L) if you want all persistent
connections closed and gone

Oleg


> On Wed, Oct 15, 2008 at 10:03 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Tue, 2008-10-14 at 17:12 -0700, Mohit Anchlia wrote:
> >> So what should be the protocol of shutting down cleanely: Below is the
> >> sample code, does the below code look ok?
> >>
> >
> > It all depends on what you are trying to achieve.
> >
> > Oleg
> >
> >
> >> public class Test {
> >>    private static  MultiThreadedHttpConnectionManager con = new
> >> MultiThreadedHttpConnectionManager();
> >>    private static void doGet(HttpClient client) {
> >>        System.out.println("CONN POOL " + con.getConnectionsInPool());
> >>        //System.out.println("DEF CON "
> >> +client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
> >>        //System.out.println("MAX CON " +
> >> client.getHttpConnectionManager().getParams().getMaxTotalConnections()
> >> );
> >>
> >>        GetMethod get = new GetMethod("http://localhost:8080/s/e");
> >>                    get.setQueryString("version=V07.08&request_type=1");
> >>             get.addRequestHeader( "Connection", "close");
> >>        try {
> >>            long statusCode = client.executeMethod(get);
> >>            System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
> >>            if (statusCode != HttpStatus.SC_OK) {
> >>                           }
> >>             Thread.sleep(1000);
> >>        } catch(IOException ioe){
> >>                ioe.printStackTrace();
> >>                    }catch (Exception e){} finally {
> >>            if (get != null) get.releaseConnection();
> >>        }
> >>    }
> >>    public static void main(String []a) throws Exception{
> >>
> >>        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
> >>        params.setDefaultMaxConnectionsPerHost(2);
> >>        //params.setMaxConnectionsPerHost(2);
> >>        params.setMaxTotalConnections(2);
> >>        con.setParams(params);
> >>
> >>        HttpClient client = new HttpClient();
> >>        client.getParams().setParameter("http.connection.timeout", new
> >> Integer(1000));
> >>       int i = 0;
> >>       while ( i++ < 500){
> >>        client = new HttpClient(con);
> >>        doGet(client);
> >>        client = null;
> >>        con.closeIdleConnections(1000l);
> >>        //con.deleteClosedConnections();
> >>       }
> >> /////////////
> >>
> >> Is using HttpClient for entire life span of servlet thread safe? I
> >> still don't understand the part where you said HttpClient will not be
> >> closed properly, would ".closeIndleConnections" or
> >> "deleteClosedConnections" along with "releaseConnections" take care of
> >> it.
> >>
> >> On Tue, Oct 14, 2008 at 3:07 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> >> > On Tue, 2008-10-14 at 23:51 +0200, Christine wrote:
> >> >> On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:
> >> >>
> >> >> > > What is the tradeoff between using the same httpClient instance again
> >> >> > > and again, or creating a new one on each request? Can you create a
> >> >> > > memory leak by using one instance and not closing connections properly?
> >> >> > >
> >> >> > It very much depends on what you are trying to accomplish. Generally it
> >> >> > is recommended to reuse the HttpClient instance in order to utilize
> >> >> > persistent connections more efficiently.
> >> >> >
> >> >> > What is very important that the connection manager associated with the
> >> >> > HttpClient instance is shut down when it is no longer needed. Otherwise,
> >> >> > connections will stay open until garbage collected by the JVM, which may
> >> >> > take a while. If too many instances of HttpClient are created in a tight
> >> >> > loop without being correctly shut down, there will be too many
> >> >> > connections kept alive needlessly and the system can run out of
> >> >> > resources.
> >> >>
> >> >> Oleg,
> >> >> thanks for the reply. I am reusing one instance, but I was just
> >> >> wondering. Using one instance I don't have to shut down connection
> >> >> managers, right?
> >> >>
> >> >
> >> > It is a little more complex than that. You do not, as long as that
> >> > instance is used for the entire lifespan of the application. One really
> >> > ought to shut down the connection manager before it goes out of scope /
> >> > becomes garbage. This is especially important for managed environments
> >> > such as servlet containers where applications can be undeployed and
> >> > redeployed.
> >> >
> >> >> btw, I'm still a bit confused after switching from 3.x to 4.0, but you
> >> >> guys have the documentation right, now. I think you did a good job.
> >> >>
> >> >
> >> > I know the documentation is still lacking. We happily take
> >> > contributions.
> >> >
> >> > Oleg
> >> >
> >> >
> >> >> Christine
> >> >>
> >> >> >
> >> >> > Hope this helps
> >> >> >
> >> >> > Oleg
> >> >> >
> >> >> >
> >> >> > > >
> >> >> > > > Oleg
> >> >> > > >
> >> >> > > > > ---------------------------------------------------------------------
> >> >> > > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> >> > > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >> > > > >
> >> >> > > >
> >> >> > > >
> >> >> > > > ---------------------------------------------------------------------
> >> >> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> >> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >> >
> >> >> >
> >> >> > ---------------------------------------------------------------------
> >> >> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> >> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
I am trying to keep CLOSE_WAIT close to 0. I also noticed that apache
libs threw error when I was using one instance of HttpClient accross
threads, that's the reason I started using one Httpclient per thread
and then releaseConnection, closeIdleConnection and deleteConnection
after every invocation of doGet in below code.

On Wed, Oct 15, 2008 at 10:03 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Tue, 2008-10-14 at 17:12 -0700, Mohit Anchlia wrote:
>> So what should be the protocol of shutting down cleanely: Below is the
>> sample code, does the below code look ok?
>>
>
> It all depends on what you are trying to achieve.
>
> Oleg
>
>
>> public class Test {
>>    private static  MultiThreadedHttpConnectionManager con = new
>> MultiThreadedHttpConnectionManager();
>>    private static void doGet(HttpClient client) {
>>        System.out.println("CONN POOL " + con.getConnectionsInPool());
>>        //System.out.println("DEF CON "
>> +client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
>>        //System.out.println("MAX CON " +
>> client.getHttpConnectionManager().getParams().getMaxTotalConnections()
>> );
>>
>>        GetMethod get = new GetMethod("http://localhost:8080/s/e");
>>                    get.setQueryString("version=V07.08&request_type=1");
>>             get.addRequestHeader( "Connection", "close");
>>        try {
>>            long statusCode = client.executeMethod(get);
>>            System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
>>            if (statusCode != HttpStatus.SC_OK) {
>>                           }
>>             Thread.sleep(1000);
>>        } catch(IOException ioe){
>>                ioe.printStackTrace();
>>                    }catch (Exception e){} finally {
>>            if (get != null) get.releaseConnection();
>>        }
>>    }
>>    public static void main(String []a) throws Exception{
>>
>>        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
>>        params.setDefaultMaxConnectionsPerHost(2);
>>        //params.setMaxConnectionsPerHost(2);
>>        params.setMaxTotalConnections(2);
>>        con.setParams(params);
>>
>>        HttpClient client = new HttpClient();
>>        client.getParams().setParameter("http.connection.timeout", new
>> Integer(1000));
>>       int i = 0;
>>       while ( i++ < 500){
>>        client = new HttpClient(con);
>>        doGet(client);
>>        client = null;
>>        con.closeIdleConnections(1000l);
>>        //con.deleteClosedConnections();
>>       }
>> /////////////
>>
>> Is using HttpClient for entire life span of servlet thread safe? I
>> still don't understand the part where you said HttpClient will not be
>> closed properly, would ".closeIndleConnections" or
>> "deleteClosedConnections" along with "releaseConnections" take care of
>> it.
>>
>> On Tue, Oct 14, 2008 at 3:07 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
>> > On Tue, 2008-10-14 at 23:51 +0200, Christine wrote:
>> >> On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:
>> >>
>> >> > > What is the tradeoff between using the same httpClient instance again
>> >> > > and again, or creating a new one on each request? Can you create a
>> >> > > memory leak by using one instance and not closing connections properly?
>> >> > >
>> >> > It very much depends on what you are trying to accomplish. Generally it
>> >> > is recommended to reuse the HttpClient instance in order to utilize
>> >> > persistent connections more efficiently.
>> >> >
>> >> > What is very important that the connection manager associated with the
>> >> > HttpClient instance is shut down when it is no longer needed. Otherwise,
>> >> > connections will stay open until garbage collected by the JVM, which may
>> >> > take a while. If too many instances of HttpClient are created in a tight
>> >> > loop without being correctly shut down, there will be too many
>> >> > connections kept alive needlessly and the system can run out of
>> >> > resources.
>> >>
>> >> Oleg,
>> >> thanks for the reply. I am reusing one instance, but I was just
>> >> wondering. Using one instance I don't have to shut down connection
>> >> managers, right?
>> >>
>> >
>> > It is a little more complex than that. You do not, as long as that
>> > instance is used for the entire lifespan of the application. One really
>> > ought to shut down the connection manager before it goes out of scope /
>> > becomes garbage. This is especially important for managed environments
>> > such as servlet containers where applications can be undeployed and
>> > redeployed.
>> >
>> >> btw, I'm still a bit confused after switching from 3.x to 4.0, but you
>> >> guys have the documentation right, now. I think you did a good job.
>> >>
>> >
>> > I know the documentation is still lacking. We happily take
>> > contributions.
>> >
>> > Oleg
>> >
>> >
>> >> Christine
>> >>
>> >> >
>> >> > Hope this helps
>> >> >
>> >> > Oleg
>> >> >
>> >> >
>> >> > > >
>> >> > > > Oleg
>> >> > > >
>> >> > > > > ---------------------------------------------------------------------
>> >> > > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> >> > > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >> > > > >
>> >> > > >
>> >> > > >
>> >> > > > ---------------------------------------------------------------------
>> >> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> >> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >> >
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> >> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-10-14 at 17:12 -0700, Mohit Anchlia wrote:
> So what should be the protocol of shutting down cleanely: Below is the
> sample code, does the below code look ok?
> 

It all depends on what you are trying to achieve.

Oleg


> public class Test {
>    private static  MultiThreadedHttpConnectionManager con = new
> MultiThreadedHttpConnectionManager();
>    private static void doGet(HttpClient client) {
>        System.out.println("CONN POOL " + con.getConnectionsInPool());
>        //System.out.println("DEF CON "
> +client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
>        //System.out.println("MAX CON " +
> client.getHttpConnectionManager().getParams().getMaxTotalConnections()
> );
> 
>        GetMethod get = new GetMethod("http://localhost:8080/s/e");
>                    get.setQueryString("version=V07.08&request_type=1");
>             get.addRequestHeader( "Connection", "close");
>        try {
>            long statusCode = client.executeMethod(get);
>            System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
>            if (statusCode != HttpStatus.SC_OK) {
>                           }
>             Thread.sleep(1000);
>        } catch(IOException ioe){
>                ioe.printStackTrace();
>                    }catch (Exception e){} finally {
>            if (get != null) get.releaseConnection();
>        }
>    }
>    public static void main(String []a) throws Exception{
> 
>        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
>        params.setDefaultMaxConnectionsPerHost(2);
>        //params.setMaxConnectionsPerHost(2);
>        params.setMaxTotalConnections(2);
>        con.setParams(params);
> 
>        HttpClient client = new HttpClient();
>        client.getParams().setParameter("http.connection.timeout", new
> Integer(1000));
>       int i = 0;
>       while ( i++ < 500){
>        client = new HttpClient(con);
>        doGet(client);
>        client = null;
>        con.closeIdleConnections(1000l);
>        //con.deleteClosedConnections();
>       }
> /////////////
> 
> Is using HttpClient for entire life span of servlet thread safe? I
> still don't understand the part where you said HttpClient will not be
> closed properly, would ".closeIndleConnections" or
> "deleteClosedConnections" along with "releaseConnections" take care of
> it.
> 
> On Tue, Oct 14, 2008 at 3:07 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Tue, 2008-10-14 at 23:51 +0200, Christine wrote:
> >> On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:
> >>
> >> > > What is the tradeoff between using the same httpClient instance again
> >> > > and again, or creating a new one on each request? Can you create a
> >> > > memory leak by using one instance and not closing connections properly?
> >> > >
> >> > It very much depends on what you are trying to accomplish. Generally it
> >> > is recommended to reuse the HttpClient instance in order to utilize
> >> > persistent connections more efficiently.
> >> >
> >> > What is very important that the connection manager associated with the
> >> > HttpClient instance is shut down when it is no longer needed. Otherwise,
> >> > connections will stay open until garbage collected by the JVM, which may
> >> > take a while. If too many instances of HttpClient are created in a tight
> >> > loop without being correctly shut down, there will be too many
> >> > connections kept alive needlessly and the system can run out of
> >> > resources.
> >>
> >> Oleg,
> >> thanks for the reply. I am reusing one instance, but I was just
> >> wondering. Using one instance I don't have to shut down connection
> >> managers, right?
> >>
> >
> > It is a little more complex than that. You do not, as long as that
> > instance is used for the entire lifespan of the application. One really
> > ought to shut down the connection manager before it goes out of scope /
> > becomes garbage. This is especially important for managed environments
> > such as servlet containers where applications can be undeployed and
> > redeployed.
> >
> >> btw, I'm still a bit confused after switching from 3.x to 4.0, but you
> >> guys have the documentation right, now. I think you did a good job.
> >>
> >
> > I know the documentation is still lacking. We happily take
> > contributions.
> >
> > Oleg
> >
> >
> >> Christine
> >>
> >> >
> >> > Hope this helps
> >> >
> >> > Oleg
> >> >
> >> >
> >> > > >
> >> > > > Oleg
> >> > > >
> >> > > > > ---------------------------------------------------------------------
> >> > > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> > > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> > > > >
> >> > > >
> >> > > >
> >> > > > ---------------------------------------------------------------------
> >> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
So what should be the protocol of shutting down cleanely: Below is the
sample code, does the below code look ok?

public class Test {
   private static  MultiThreadedHttpConnectionManager con = new
MultiThreadedHttpConnectionManager();
   private static void doGet(HttpClient client) {
       System.out.println("CONN POOL " + con.getConnectionsInPool());
       //System.out.println("DEF CON "
+client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
       //System.out.println("MAX CON " +
client.getHttpConnectionManager().getParams().getMaxTotalConnections()
);

       GetMethod get = new GetMethod("http://localhost:8080/s/e");
                   get.setQueryString("version=V07.08&request_type=1");
            get.addRequestHeader( "Connection", "close");
       try {
           long statusCode = client.executeMethod(get);
           System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
           if (statusCode != HttpStatus.SC_OK) {
                          }
            Thread.sleep(1000);
       } catch(IOException ioe){
               ioe.printStackTrace();
                   }catch (Exception e){} finally {
           if (get != null) get.releaseConnection();
       }
   }
   public static void main(String []a) throws Exception{

       HttpConnectionManagerParams params = new HttpConnectionManagerParams();
       params.setDefaultMaxConnectionsPerHost(2);
       //params.setMaxConnectionsPerHost(2);
       params.setMaxTotalConnections(2);
       con.setParams(params);

       HttpClient client = new HttpClient();
       client.getParams().setParameter("http.connection.timeout", new
Integer(1000));
      int i = 0;
      while ( i++ < 500){
       client = new HttpClient(con);
       doGet(client);
       client = null;
       con.closeIdleConnections(1000l);
       //con.deleteClosedConnections();
      }
/////////////

Is using HttpClient for entire life span of servlet thread safe? I
still don't understand the part where you said HttpClient will not be
closed properly, would ".closeIndleConnections" or
"deleteClosedConnections" along with "releaseConnections" take care of
it.

On Tue, Oct 14, 2008 at 3:07 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Tue, 2008-10-14 at 23:51 +0200, Christine wrote:
>> On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:
>>
>> > > What is the tradeoff between using the same httpClient instance again
>> > > and again, or creating a new one on each request? Can you create a
>> > > memory leak by using one instance and not closing connections properly?
>> > >
>> > It very much depends on what you are trying to accomplish. Generally it
>> > is recommended to reuse the HttpClient instance in order to utilize
>> > persistent connections more efficiently.
>> >
>> > What is very important that the connection manager associated with the
>> > HttpClient instance is shut down when it is no longer needed. Otherwise,
>> > connections will stay open until garbage collected by the JVM, which may
>> > take a while. If too many instances of HttpClient are created in a tight
>> > loop without being correctly shut down, there will be too many
>> > connections kept alive needlessly and the system can run out of
>> > resources.
>>
>> Oleg,
>> thanks for the reply. I am reusing one instance, but I was just
>> wondering. Using one instance I don't have to shut down connection
>> managers, right?
>>
>
> It is a little more complex than that. You do not, as long as that
> instance is used for the entire lifespan of the application. One really
> ought to shut down the connection manager before it goes out of scope /
> becomes garbage. This is especially important for managed environments
> such as servlet containers where applications can be undeployed and
> redeployed.
>
>> btw, I'm still a bit confused after switching from 3.x to 4.0, but you
>> guys have the documentation right, now. I think you did a good job.
>>
>
> I know the documentation is still lacking. We happily take
> contributions.
>
> Oleg
>
>
>> Christine
>>
>> >
>> > Hope this helps
>> >
>> > Oleg
>> >
>> >
>> > > >
>> > > > Oleg
>> > > >
>> > > > > ---------------------------------------------------------------------
>> > > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> > > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> > > > >
>> > > >
>> > > >
>> > > > ---------------------------------------------------------------------
>> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
> >> Just one. One can make several HttpClient instances share the same
> >> connection manager, though, (which is not recommended).
> 
> Why is multiple HttpClients and one connection manager not
> recommended? I tried using one HttpClient in servlet accross all the
> threads but started getting errors. It looks like I can't use one
> instance of HttpClient shared accross multiple threads at the same
> time
> 

Yes, you can. HttpClient is threading safe as long as it is used with a
threading safe connection manager.

Oleg


> On Wed, Oct 15, 2008 at 10:34 AM, Christine <ch...@christine.nl> wrote:
> > On Wed, 2008-10-15 at 19:08 +0200, Oleg Kalnichevski wrote:
> >
> >> Just one. One can make several HttpClient instances share the same
> >> connection manager, though, (which is not recommended).
> >
> > Got it. Thanks!
> >
> > Christine
> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > --
> > dagdag is just a two character rotation of byebye
> > www.christine.nl
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-10-15 at 14:32 -0700, Mohit Anchlia wrote:
> Is it possible to give me few words on why it doesn't have tangible
> benefit.

I personally do not see any. 

Oleg

>  I think I am missing your point here. May be I don't
> understand HttpClient.
> 
> On Wed, Oct 15, 2008 at 2:09 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Wed, 2008-10-15 at 11:11 -0700, Mohit Anchlia wrote:
> >> thanks. But can I share same HttpClient accross threads or do I need
> >> to synchronize for each thread. I am still not sure why was I getting
> >> errors when I tries using one instance of HttpClient accross threads.
> >>
> >> Another question I have is can I use same multithreadedConnection
> >> manager for different instances of HttpClient?
> >
> > Yes, you can, but it just does not give you any tangible benefit.
> >
> > Oleg
> >
> >
> >>  I am assuming
> >> multithreadedConnectionManager is thread safe and could be used in
> >> servlet env.
> >>
> >> On Wed, Oct 15, 2008 at 10:44 AM, Christine <ch...@christine.nl> wrote:
> >> > On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
> >> >> >> Just one. One can make several HttpClient instances share the same
> >> >> >> connection manager, though, (which is not recommended).
> >> >>
> >> >> Why is multiple HttpClients and one connection manager not
> >> >> recommended? I tried using one HttpClient in servlet accross all the
> >> >> threads but started getting errors. It looks like I can't use one
> >> >> instance of HttpClient shared accross multiple threads at the same
> >> >> time
> >> >
> >> > Wouldn't it be easier to have one service in a separate thread that
> >> > handles all http so you can have one HttpClient that is used by all
> >> > threads?
> >> >
> >> > Christine
> >> >
> >> >
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> > --
> >> > dagdag is just a two character rotation of byebye
> >> > www.christine.nl
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
Is it possible to give me few words on why it doesn't have tangible
benefit. I think I am missing your point here. May be I don't
understand HttpClient.

On Wed, Oct 15, 2008 at 2:09 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2008-10-15 at 11:11 -0700, Mohit Anchlia wrote:
>> thanks. But can I share same HttpClient accross threads or do I need
>> to synchronize for each thread. I am still not sure why was I getting
>> errors when I tries using one instance of HttpClient accross threads.
>>
>> Another question I have is can I use same multithreadedConnection
>> manager for different instances of HttpClient?
>
> Yes, you can, but it just does not give you any tangible benefit.
>
> Oleg
>
>
>>  I am assuming
>> multithreadedConnectionManager is thread safe and could be used in
>> servlet env.
>>
>> On Wed, Oct 15, 2008 at 10:44 AM, Christine <ch...@christine.nl> wrote:
>> > On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
>> >> >> Just one. One can make several HttpClient instances share the same
>> >> >> connection manager, though, (which is not recommended).
>> >>
>> >> Why is multiple HttpClients and one connection manager not
>> >> recommended? I tried using one HttpClient in servlet accross all the
>> >> threads but started getting errors. It looks like I can't use one
>> >> instance of HttpClient shared accross multiple threads at the same
>> >> time
>> >
>> > Wouldn't it be easier to have one service in a separate thread that
>> > handles all http so you can have one HttpClient that is used by all
>> > threads?
>> >
>> > Christine
>> >
>> >
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> > --
>> > dagdag is just a two character rotation of byebye
>> > www.christine.nl
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-10-15 at 11:11 -0700, Mohit Anchlia wrote:
> thanks. But can I share same HttpClient accross threads or do I need
> to synchronize for each thread. I am still not sure why was I getting
> errors when I tries using one instance of HttpClient accross threads.
> 
> Another question I have is can I use same multithreadedConnection
> manager for different instances of HttpClient?

Yes, you can, but it just does not give you any tangible benefit. 

Oleg


>  I am assuming
> multithreadedConnectionManager is thread safe and could be used in
> servlet env.
> 
> On Wed, Oct 15, 2008 at 10:44 AM, Christine <ch...@christine.nl> wrote:
> > On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
> >> >> Just one. One can make several HttpClient instances share the same
> >> >> connection manager, though, (which is not recommended).
> >>
> >> Why is multiple HttpClients and one connection manager not
> >> recommended? I tried using one HttpClient in servlet accross all the
> >> threads but started getting errors. It looks like I can't use one
> >> instance of HttpClient shared accross multiple threads at the same
> >> time
> >
> > Wouldn't it be easier to have one service in a separate thread that
> > handles all http so you can have one HttpClient that is used by all
> > threads?
> >
> > Christine
> >
> >
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > --
> > dagdag is just a two character rotation of byebye
> > www.christine.nl
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
thanks. But can I share same HttpClient accross threads or do I need
to synchronize for each thread. I am still not sure why was I getting
errors when I tries using one instance of HttpClient accross threads.

Another question I have is can I use same multithreadedConnection
manager for different instances of HttpClient? I am assuming
multithreadedConnectionManager is thread safe and could be used in
servlet env.

On Wed, Oct 15, 2008 at 10:44 AM, Christine <ch...@christine.nl> wrote:
> On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
>> >> Just one. One can make several HttpClient instances share the same
>> >> connection manager, though, (which is not recommended).
>>
>> Why is multiple HttpClients and one connection manager not
>> recommended? I tried using one HttpClient in servlet accross all the
>> threads but started getting errors. It looks like I can't use one
>> instance of HttpClient shared accross multiple threads at the same
>> time
>
> Wouldn't it be easier to have one service in a separate thread that
> handles all http so you can have one HttpClient that is used by all
> threads?
>
> Christine
>
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> --
> dagdag is just a two character rotation of byebye
> www.christine.nl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Christine <ch...@christine.nl>.
On Wed, 2008-10-15 at 10:40 -0700, Mohit Anchlia wrote:
> >> Just one. One can make several HttpClient instances share the same
> >> connection manager, though, (which is not recommended).
> 
> Why is multiple HttpClients and one connection manager not
> recommended? I tried using one HttpClient in servlet accross all the
> threads but started getting errors. It looks like I can't use one
> instance of HttpClient shared accross multiple threads at the same
> time

Wouldn't it be easier to have one service in a separate thread that
handles all http so you can have one HttpClient that is used by all
threads? 

Christine


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
>> Just one. One can make several HttpClient instances share the same
>> connection manager, though, (which is not recommended).

Why is multiple HttpClients and one connection manager not
recommended? I tried using one HttpClient in servlet accross all the
threads but started getting errors. It looks like I can't use one
instance of HttpClient shared accross multiple threads at the same
time

On Wed, Oct 15, 2008 at 10:34 AM, Christine <ch...@christine.nl> wrote:
> On Wed, 2008-10-15 at 19:08 +0200, Oleg Kalnichevski wrote:
>
>> Just one. One can make several HttpClient instances share the same
>> connection manager, though, (which is not recommended).
>
> Got it. Thanks!
>
> Christine
>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> --
> dagdag is just a two character rotation of byebye
> www.christine.nl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Christine <ch...@christine.nl>.
On Wed, 2008-10-15 at 19:08 +0200, Oleg Kalnichevski wrote:

> Just one. One can make several HttpClient instances share the same
> connection manager, though, (which is not recommended).

Got it. Thanks!

Christine

> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-10-15 at 16:44 +0200, Christine wrote:
> On Wed, 2008-10-15 at 00:07 +0200, Oleg Kalnichevski wrote:
> 
> > It is a little more complex than that. You do not, as long as that
> > instance is used for the entire lifespan of the application. One really
> > ought to shut down the connection manager before it goes out of scope /
> > becomes garbage. This is especially important for managed environments
> > such as servlet containers where applications can be undeployed and
> > redeployed.
> 
> Does "this instance" refer to the HttpClient, or to the
> connectionmanager?

Connection manager

>  I use one instance of DefaultHttpClient during the
> lifetime of my application. Does this client create new connection
> managers that I have to shutdown, or does it use one connectionmanager?
> 

Just one. One can make several HttpClient instances share the same
connection manager, though, (which is not recommended).

Oleg


> Christine
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Christine <ch...@christine.nl>.
On Wed, 2008-10-15 at 00:07 +0200, Oleg Kalnichevski wrote:

> It is a little more complex than that. You do not, as long as that
> instance is used for the entire lifespan of the application. One really
> ought to shut down the connection manager before it goes out of scope /
> becomes garbage. This is especially important for managed environments
> such as servlet containers where applications can be undeployed and
> redeployed.

Does "this instance" refer to the HttpClient, or to the
connectionmanager? I use one instance of DefaultHttpClient during the
lifetime of my application. Does this client create new connection
managers that I have to shutdown, or does it use one connectionmanager?

Christine

-- 
dagdag is just a two character rotation of byebye
www.christine.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-10-14 at 23:51 +0200, Christine wrote:
> On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:
> 
> > > What is the tradeoff between using the same httpClient instance again
> > > and again, or creating a new one on each request? Can you create a
> > > memory leak by using one instance and not closing connections properly?
> > > 
> > It very much depends on what you are trying to accomplish. Generally it
> > is recommended to reuse the HttpClient instance in order to utilize
> > persistent connections more efficiently.
> > 
> > What is very important that the connection manager associated with the
> > HttpClient instance is shut down when it is no longer needed. Otherwise,
> > connections will stay open until garbage collected by the JVM, which may
> > take a while. If too many instances of HttpClient are created in a tight
> > loop without being correctly shut down, there will be too many
> > connections kept alive needlessly and the system can run out of
> > resources.
> 
> Oleg,
> thanks for the reply. I am reusing one instance, but I was just
> wondering. Using one instance I don't have to shut down connection
> managers, right?
> 

It is a little more complex than that. You do not, as long as that
instance is used for the entire lifespan of the application. One really
ought to shut down the connection manager before it goes out of scope /
becomes garbage. This is especially important for managed environments
such as servlet containers where applications can be undeployed and
redeployed.

> btw, I'm still a bit confused after switching from 3.x to 4.0, but you
> guys have the documentation right, now. I think you did a good job. 
> 

I know the documentation is still lacking. We happily take
contributions. 

Oleg


> Christine
> 
> > 
> > Hope this helps
> > 
> > Oleg
> > 
> > 
> > > > 
> > > > Oleg
> > > > 
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > > > > 
> > > > 
> > > > 
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Christine <ch...@christine.nl>.
On Tue, 2008-10-14 at 23:44 +0200, Oleg Kalnichevski wrote:

> > What is the tradeoff between using the same httpClient instance again
> > and again, or creating a new one on each request? Can you create a
> > memory leak by using one instance and not closing connections properly?
> > 
> It very much depends on what you are trying to accomplish. Generally it
> is recommended to reuse the HttpClient instance in order to utilize
> persistent connections more efficiently.
> 
> What is very important that the connection manager associated with the
> HttpClient instance is shut down when it is no longer needed. Otherwise,
> connections will stay open until garbage collected by the JVM, which may
> take a while. If too many instances of HttpClient are created in a tight
> loop without being correctly shut down, there will be too many
> connections kept alive needlessly and the system can run out of
> resources.

Oleg,
thanks for the reply. I am reusing one instance, but I was just
wondering. Using one instance I don't have to shut down connection
managers, right?

btw, I'm still a bit confused after switching from 3.x to 4.0, but you
guys have the documentation right, now. I think you did a good job. 

Christine

> 
> Hope this helps
> 
> Oleg
> 
> 
> > > 
> > > Oleg
> > > 
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > > > 
> > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-10-14 at 09:58 +0200, Christine wrote:
> On Mon, 2008-10-13 at 23:41 +0200, Oleg Kalnichevski wrote:
> > On Mon, 2008-10-13 at 10:45 -0700, Mohit Anchlia wrote:
> > > What happens when an instance of HttpClient instance is created for
> > > each request? Does it internally get associated with one Connection
> > > manager or there is new connection manager created for each HttpClient
> > > instance?
> > > 
> > 
> > New connection manager created for each HttpClient instance
> 
> What is the tradeoff between using the same httpClient instance again
> and again, or creating a new one on each request? Can you create a
> memory leak by using one instance and not closing connections properly?
> 
> Christine
> 

Christine,

It very much depends on what you are trying to accomplish. Generally it
is recommended to reuse the HttpClient instance in order to utilize
persistent connections more efficiently.

What is very important that the connection manager associated with the
HttpClient instance is shut down when it is no longer needed. Otherwise,
connections will stay open until garbage collected by the JVM, which may
take a while. If too many instances of HttpClient are created in a tight
loop without being correctly shut down, there will be too many
connections kept alive needlessly and the system can run out of
resources.

Hope this helps

Oleg


> > 
> > Oleg
> > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Christine <ch...@christine.nl>.
On Mon, 2008-10-13 at 23:41 +0200, Oleg Kalnichevski wrote:
> On Mon, 2008-10-13 at 10:45 -0700, Mohit Anchlia wrote:
> > What happens when an instance of HttpClient instance is created for
> > each request? Does it internally get associated with one Connection
> > manager or there is new connection manager created for each HttpClient
> > instance?
> > 
> 
> New connection manager created for each HttpClient instance

What is the tradeoff between using the same httpClient instance again
and again, or creating a new one on each request? Can you create a
memory leak by using one instance and not closing connections properly?

Christine

> 
> Oleg
> 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
-- 
dagdag is just a two character rotation of byebye
www.christine.nl


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Multiple calls to HttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2008-10-13 at 10:45 -0700, Mohit Anchlia wrote:
> What happens when an instance of HttpClient instance is created for
> each request? Does it internally get associated with one Connection
> manager or there is new connection manager created for each HttpClient
> instance?
> 

New connection manager created for each HttpClient instance

Oleg

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org