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 vj...@mmm.com on 2006/10/20 18:16:04 UTC

HttpClient Static instance

What is issue that might arise by keeping the HttpClient instance static in
a Utility class.

Before I use the static instance of the httpClient I make the check and
initialize it.

Please let me know if there is a better way to implement this?


            //Initialize the HttpClient & enable Concurrent execution of
HTTPmethods
            if(httpClient==null) {
                  MultiThreadedHttpConnectionManager connectionManager =
                        new MultiThreadedHttpConnectionManager();
                  httpClient = new HttpClient(connectionManager);

                  /*Set the proxy*/
                  if (proxy != null) {
                        httpClient.getHostConfiguration().setProxy(proxy,
proxyPort);
                  }
            }

Thanks & Regards,
Vasanth.


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


Re: HttpClient Static instance

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2006-10-20 at 11:16 -0500, vjayakumar@mmm.com wrote:
> What is issue that might arise by keeping the HttpClient instance static in
> a Utility class.
> 

Vasanth,

I apologize for such a latest response. Users are very much encouraged
to re-use HttpClient instance(s), so I see nothing wrong in keeping a
static instance in a utility class.

Oleg


> Before I use the static instance of the httpClient I make the check and
> initialize it.
> 
> Please let me know if there is a better way to implement this?
> 
> 
>             //Initialize the HttpClient & enable Concurrent execution of
> HTTPmethods
>             if(httpClient==null) {
>                   MultiThreadedHttpConnectionManager connectionManager =
>                         new MultiThreadedHttpConnectionManager();
>                   httpClient = new HttpClient(connectionManager);
> 
>                   /*Set the proxy*/
>                   if (proxy != null) {
>                         httpClient.getHostConfiguration().setProxy(proxy,
> proxyPort);
>                   }
>             }
> 
> Thanks & Regards,
> Vasanth.
> 
> 
> ---------------------------------------------------------------------
> 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