Re: An Executor-like structure providing more than threads
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
--
Why did one straw break the camel's back? Here's the secret: the million
other straws underneath it - it's all mathematics. -- Mos Def