No Cheeso, there is no general object pool like this. But it is a good idea. I think this would be pretty simple to develop. The key thing is making it work well in a threaded environment.
I think this is an interesting design problem. For example, if this needs to to scale on sever class hardware -and- you will give objects to indivudual threads often then you might do this:
- Keep a single central pool of objects.
- Keep a per-thread pool (a cache) that is populated when its called for the first time for a thread, and when it becomes empty.
This way, you avoid per-thread contention for most requests.
Different operational conditions would lead you to a different design. For example, if object allocations are rare or the number of threads is low, then it might be simpler just to have a lock around a collection. This won't scale well, but in this case, it would need to.
If you design the class or interface correctly, then you could change the implementation over time to handle more complex scenarios.