title: C# Object Pooling Pattern implementation
body: <p>Does anyone have a good resource on implementing a shared object pool strategy for a limited resource in vein of Sql connection pooling? (ie would be implemented fully that it is thread safe).</p>
  
  <p>To follow up in regards to @Aaronaught request for clarification the pool usage would be for load balancing requests to an external service. To put it in a scenario that would probably be easier to immediately understand as opposed to my direct situtation. I have a session object that functions similarly to the <code>ISession</code> object from NHibernate. That each unique session manages it's connection to the database. Currently I have 1 long running session object and am encountering issues where my service provider is rate limiting my usage of this individual session.</p>
  
  <p>Due to their lack of expectation that a single session would be treated as a long running service account they apparently treat it as a client that is hammering their service. Which brings me to my question here, instead of having 1 individual session I would create a pool of different sessions and split the requests up to the service across those multiple sessions instead of creating a single focal point as I was previously doing.</p>
  
  <p>Hopefully that background offers some value but to directly answer some of your questions:</p>
  
  <p><strong>Q:</strong> Are the objects expensive to create?<br>
  <strong>A:</strong> No objects are a pool of limited resources</p>
  
  <p><strong>Q:</strong> Will they be acquired/released very frequently?<br>
  <strong>A:</strong> Yes, once again they can be thought of NHibernate ISessions where 1 is usually acquired and released for the duration of every single page request.</p>
  
  <p><strong>Q:</strong> Will a simple first-come-first-serve suffice or do you need something more intelligent, i.e. that would prevent starvation?<br>
  <strong>A:</strong> A simple round robin type distribution would suffice, by starvation I assume you mean if there are no available sessions that callers become blocked waiting for releases. This isn't really applicable since the sessions can be shared by different callers. My goal is distribute the usage across multiple sessions as opposed to 1 single session.</p>
  
  <p>I believe this is probably a divergence from a normal usage of an object pool which is why I originally left this part out and planned just to adapt the pattern to allow sharing of objects as opposed to allowing a starvation situation to ever occur.</p>
  
  <p><strong>Q:</strong> What about things like priorities, lazy vs. eager loading, etc.?<br>
  <strong>A:</strong> There is no prioritization involved, for simplicity's sake just assume that I would create the pool of available objects at the creation of the pool itself.</p>