You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Juan Pedro López Sáez <jp...@altiria.com> on 2004/06/15 16:00:35 UTC

Some question about the multithreaded manager

Hello everybody.

I'm about starting to use the MultipleThreadedHttpConnectionManager but
after reading the documentation, I have some questions:

- Is it possible to set different values for MAX_HOST_CONNECTION, in a
per HOST basis? My application has to connect to some host and I'd like
to set different values for everyone. Maybe using different HttpClient
objects, each one with a different manager?

- What happens if MAX_HOST_CONNECTION is exceeded and
HttpClient.executeMethod(HttpMethod) is called again? Can I wait until a
connection is released?

- Is MAX_TOTAL_CONNECTION a global value per application or just per
manager? I'd also like to set independent different values depending on
some cases. Is it possible, anyway?

- Is there any trouble in using one HttpClient object with the
multithreaded manager and another one with the simple manager, provided
that both objects will hit different hosts?

AFAIK, HostConfiguration class has nothing to do with the relative path
of an URI, I mean, it just stores information about the host IP and
port. Is it right? 

Finally, I'd like you to tell me if the following code structure is
aproppiate:

My application is composed by a MainThread which starts threads on
demand (ConnectionThreads). Every new ConnectionThread connects to a
given host and do its job.

I want to program a class, ConnectionClass, where I will put a static
HttpClient attribute initialized with the multithreaded manager, and
some methods to use this HttpClient object (connect to a host, get its
response ...)

Everytime a ConnectionThread runs, it will create a ConnectionClass
object to do its job. As HttpClient is static, it will be created just
once. 

I want every ConnectionThread to share the same HttpClient, so that I
can take advantage of the multithreaded manager and its connection pool.

Thank you very much.

	Juan Pedro López





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


Re: Some question about the multithreaded manager

Posted by Michael Becke <be...@u.washington.edu>.
Hello Juan,

Sounds like you've thought this through pretty well.  Your overall plan 
sound good.  Please find my specific comments below:

> - Is it possible to set different values for MAX_HOST_CONNECTION, in a
> per HOST basis? My application has to connect to some host and I'd like
> to set different values for everyone. Maybe using different HttpClient
> objects, each one with a different manager?

Currently it is not possible to set different values per host.  The only 
way to accomplish this would be with different connection managers, one 
per host.  Please file a enhancement request in bugzilla for this, and I 
will look into adding it for HttpClient 3.0.

> - What happens if MAX_HOST_CONNECTION is exceeded and
> HttpClient.executeMethod(HttpMethod) is called again? Can I wait until a
> connection is released?

This will cause the calling thread to block until a connection is 
available.  This wait time can be configured using 
HttpClient.setHttpConnectionFactoryTimeout().

> - Is MAX_TOTAL_CONNECTION a global value per application or just per
> manager? I'd also like to set independent different values depending on
> some cases. Is it possible, anyway?

It is a per connection manager variable.

> - Is there any trouble in using one HttpClient object with the
> multithreaded manager and another one with the simple manager, provided
> that both objects will hit different hosts?

Nope, no problem here.  They could even hit the same host if you like. 
There is no enforced relationship between instances of connection managers.

> AFAIK, HostConfiguration class has nothing to do with the relative path
> of an URI, I mean, it just stores information about the host IP and
> port. Is it right? 

This is correct.  The HostConfiguration is mean to encompass all 
information required to describe a connection path to a particular host. 
  This includes remote host/port, protocol (HTTP, HTTPS, etc.), proxy 
host/port, and local host/port.  It does not include information about 
specific resources on the server, these are specified on a per method 
basis via the request URI(path/query components).

> Finally, I'd like you to tell me if the following code structure is
> aproppiate:
> 
...
> I want every ConnectionThread to share the same HttpClient, so that I
> can take advantage of the multithreaded manager and its connection pool.

This sounds like a reasonable scenario.  I believe that a number of 
HttpClient users are doing similar things.  The only other item to 
consider is the HttpState.  The HttpState stores credentials and cookies 
used for processing requests.  Depending on what each of the threads is 
doing you may or may not want to use the same HttpState for all requests.

Mike

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