Roger Schefer wrote:
Thanks a lot Oleg - I appreciate Your help! I create the HttpClient instance in the init() method of the servlet like this:

        HttpConnectionManagerParams params;
        m_connectionmgr=new MultiThreadedHttpConnectionManager();
        params=new HttpConnectionManagerParams();
        params.setConnectionTimeout(this.CONNECT_TIMEOUT);
        params.setSoTimeout(this.READ_TIMEOUT);
        params.setDefaultMaxConnectionsPerHost(3000);
        params.setMaxTotalConnections(3000);
        m_connectionmgr.setParams(params);
        m_httpclient=new HttpClient(m_connectionmgr);
m_httpclient.getHostConfiguration().setProxy(this.PROXY_SERVER, this.PROXY_PORT);
        m_httpclient.getState().setProxyCredentials(
new AuthScope(this.PROXY_SERVER, this.PROXY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(this.PROXY_USERNAME, this.PROXY_PASSWORD) );

Also, in destroy() I call m_connectionmgr.shutdown() as recommended in the performance guide.

Does the above code make sense?


Looks all right to me.


The servlet sends a head request to one of
3 URLs all on the same host in doGet() using the HttpClient instance. I am not sure about the DefaultMaxConnectionsPerHost and MaxTotalConnections settings, which I think in this case have the same effect. Does DefaultMaxConnectionsPerHost mean that max 3000 head requests can be sent in parallel fired from 3000 calls to the servlet?

Yes, it does.

What happens if browser
3001 calls the servlet?


The request will block until a connection becomes available

Oleg

Thank You for Your help!






Oleg Kalnichevski <[email protected]> 11.12.2008 16:56
Please respond to
"HttpClient User Discussion" <[email protected]>


To
HttpClient User Discussion <[email protected]>
cc

Subject
Re: When to best initialize HttpClient & How set timeout?






On Wed, 2008-12-10 at 23:09 +0100, Roger Schefer wrote:
Hi all,

I am using httpclient 3.1 in a servlet to check if a URL is alive or
not.
When should I best initialize HttpClient? I was thinking to create a HttpClient instance in the servlet constructor and to execute a
HeadMethod
in the doGet method of the servlet. Is this the right way to do it

Yes, it is. Make sure to use a threading safe connection manager with
HttpClient, though.


or should I better create a new instance of HttpClient in doGet for each request?

Also, I want the HeadMethod to stop after a certain amount of time. How can I set a timeout? I am using
HttpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeOut)
and HttpClient.getHttpConnectionManager().getParams().setSoTimeout(timeOut),

but there is also HttpClient.getParams().setSoTimeout(timeOut), HttpClient.getParams().setParameter("http.socket.timeout", new Integer(timeOut)), HttpClient.getParams().setConnectionManagerTimeout(timeOut), HeadMethod.getParams().setParameter("http.socket.timeout", new Integer(timeOut)) and HostConfiguration.getParams().setParameter("http.socket.timeout", timeOut). What is the difference between them?


Please refer to the HttpClient preference architecture guide.

Oleg

Many thanks for any help!


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]






---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to