hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rezaei, Mohammad A." <mohammad.rez...@gs.com>
Subject RE: DO NOT REPLY [Bug 28296] - [API Doc] Compile performance opt imization guide
Date Mon, 27 Dec 2004 15:41:45 GMT
I just re-read the first part of the guide (Reuse of HttpClient instance),
and I think I'm a little confused. How can the instance of HttpClient be
reused in a thread safe manner (without single threading that instance)? 

Let me describe how I've setup httpclient and see if you guys think it's
less than optimal. I've setup a factory class that has this code in it:

    private static MultiThreadedHttpConnectionManager httpConnectionManager
= new MultiThreadedHttpConnectionManager();

    static
    {
        HttpConnectionManagerParams params =
httpConnectionManager.getParams();
 
params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
5);
        params.setStaleCheckingEnabled(true);
        params.setSoTimeout(0);
        params.setConnectionTimeout(20000);
        new IdleConnectionCloser(httpConnectionManager).start();
    }

    public static HttpClient getHttpClient(URL url)
    {
        HttpClient httpClient = new HttpClient(httpConnectionManager);
        httpClient.getHostConfiguration().setHost(url.getHost(),
url.getPort());
        return httpClient;
    }

The other pieces of code that use httpclient call
factory.getHttpClient(url), use the instance and throw it away at the end of
the method. The methods in question can be called from multiple threads.

Getting back to the guide, what I find troublesome about the first part is
that it identifies a bad usage scenario, but does not provide a solution. Am
I missing something obvious?

Thanks
Moh

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


Mime
View raw message