[Mono-devel-list] Sharing, Memory, and Collection Pools

Francisco Figueiredo Jr. fxjrlists at yahoo.com.br
Tue Feb 10 19:08:05 EST 2004

Met @ Uber wrote:
> I have a object pool that holds database connections which I would like
> other programs to make use of.  So a common example would be a a client
> application making a soap request to a server which grabs a connection
> from the pool to run its queries.  While this first request is still
> being processed, another person via soap request some other information
> from the server, which grabs another connection from the pool.  Since
> these request seem like a start and stop of a process, does the
> connection pool get re-instantiated with each request? 
 > So if I hit the
 > server, does it turn on the pool and then turn it off at the end of my
 > request, subsequently doing that each time a user hits hits a page? 
  > If
 > so, is there a way that I can make the pool stay open between requests
 > so that it can appropriately pass off connections for use (which seems
 > like the best way - so you do not have to continually start and stop
 > database connections).

The fact the connection pool get re-instantiated with each request 
depends on how you hold the connection pool object reference.

Suppose an object of the class ConnectionPoolManager.

if you instantiate a new ConnectionPoolManager each time you did the 
request, you would end up with a reinstantiation with each request.

The trick here to avoid that is to make the instance "static". Which 
means it will have only one, or as many instances as you want, and they 
would "remain" in memory between requests.

To get just one instance you would apply the singleton pattern.

The idea of the static here is that the reference would have its 
lifetime tied to the application domain which first loaded the class 
which holds the static instance. This way, only if this class is 
reloaded in the app domain is that it would remove the instance.

So, if you have the connection pool manager as an static instance, you 
wouldn't have re-instantiations between each request.

> How would something like this be done in C#/.NET?  Is it a way I compile
> a .dll or does it have to do with the way XSP/Apache/IIS service a
> request?

You can do it with plain c#. Just create you .dll with a function which 
create a static reference to your ConnectionPoolManager object and you 
are ready. :)

I hope it helps.


Francisco Figueiredo Jr.
Membro Fundador do Projeto MonoBrasil - MonoBrasil Project Founder Member

"Science without religion is lame;
religion without science is blind."

                   ~ Albert Einstein

More information about the Mono-devel-list mailing list