On Tue, Oct 11, 2005 at 10:52:03AM +0200, Keesjan van Bunningen wrote:
> For each request to a remote server I create a new instance of MyClass that
> uses/wraps HttpClient.
>
> 1. Can I use a single instance of the HttpClient (as a static field) inside
> MyClass or do I need to instantiate a new one for each new instance of
> MyClass?
> Because I use authentication and the credentials are set on the client, I
> presume I require a new instance for each request.
>
> 2. If I require a new instance of HttpClient for each instance of MyClass,
> how do I share the multi-threaded connection manager? Can I include the
> MultiThreadedHttpConnectionManager as a static field in MyClass and pass this
> as the parameter in the constructor of HttpClient?
>
> 3. If I want to apply new connection settings on-the-fly, is it possible/wise
> to update these settings in the existing connection manager? For instance,
> what happens if the MaxTotalConnections is currently set to 10 and the
> connection manager has 10 connections open, but I change the
> MaxTotalConnections value to 6?
>
Generally it is possible to update settings in the existing connection
manager on-the-fly. The exact behaviour is however implementation
specific. As far as the MTHCM is concerned, if the number of maximum
connections is increased, the new setting will have an immediate
effect. If the number of maximum connections is decreased and there
are more connections in the pool for the given host, the new setting
will have no effect.
Oleg
> class MyClass {
> private static final HttpConnectionManager manager = new
> MultiThreadedHttpConnectionManager();
> private HttpClient client;
>
> public MyClass() {
> init();
> }
>
> private void init() {
> int maxConnections = (...) // loaded on-the-fly and may change over time
>
> this.client = new HttpClient(manager);
> // set/update settings
>
> this.client.getHttpConnectionManager().getParams().setMaxTotalConnections(maxConnections);
> }
>
> (...)
> }
>
>
> Kind regards,
>
> Keesjan van Bunningen
>
> Finalist IT Group - The Netherlands
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]