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