Hello Keesjan,

you should keep a separate HttpState for each user of MyClass.
Authentication credentials and cookies are set in the HttpState,
and the HttpClient provides only a default HttpState. There is
no need to have different HttpClient objects if you pass the
HttpState explicitly when executing a method.

A static attribute should do just fine for either 1 or 2.

3 will have to be answered by somebody else.

cheers,
  Roland




"Keesjan van Bunningen" <[EMAIL PROTECTED]> 
11.10.2005 10:52
Please respond to
"HttpClient User Discussion"


To
<[email protected]>
cc

Subject
Use a single or multiple client instances?






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?
 
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]

Reply via email to