On Sat, 16 Jan 2010, Daniel Pitts wrote:
Tom Anderson wrote:
What if the resource needed to perform a task, the thing you wanted
to maintain a limited pool of, reuse, and provide shared access to,
was more than a Thread?
The pattern you are asking about is called a Resource Pool. I
wouldn't combine the concept of Thread Pool with HttpClient Pool.
They are orthogonal concepts, so they should be accessible orthogonally.
Except there's a 1:1 relationship between threads and HttpClients. Yes,
you could write a task which looked like:
public void run() {
HttpClient client = httpClientPool.acquire();
// do stuff
httpClientPool.release(client);
}
But that seems like unnecessary boilerplate. Still, it is actually less
code than my smartarse solution, so maybe it's the right answer.
It would deal gracefully with the case where a task needs no HttpClient,
or more than one, which mine doesn't. I wouldn't anticipate those being
common, though.
tom
solution is re-using the same connection manager... Perhaps you're
HttpClient pooling.
*then*, consider profiling your code. If it turns out that there is a
should consider pooling.