I would like to develop database connection pooling.
Could anyone please tell me about which data structure need to use to maintain the pool ?
I would like to develop database connection pooling.
Could anyone please tell me about which data structure need to use to maintain the pool ?
Instead of developing your own why not use a library like Commons DBCP that is widely used and well tested.
See this Sun Developer Tutorial: Connection Pooling:
In releases prior to JDBC 2.0 every database session requires a new connection and login even if the previous connection and login used the same table and user account. If you are using a JDBC release prior to 2.0 and want to improve performance, you can cache JDBC connections instead.
Not sure it's wise to create your own.
I've used c3p0 connection pooling (with Hibernate) across many projects with great success
See http://www.javaworld.com/jw-06-1998/jw-06-object-pool.html. Good luck!
It should be implemented using Object Pool desing pattern. You can read about it in
Kircher, Michael; Prashant Jain; (2002-07-04). "Pooling Pattern". EuroPLoP 2002. Retrieved on 2007-06-09. or in Object Pool Design Pattern. Java implementation for ObjectPool
and JDBCConnectionPool
classes can be found here.
Object Pool is usually a singleton with two collections of objects (e.g. database connections) inside:
This collections can be implemented as Lists
or HashTables
or something else, depends on your needs. For simple ObjectPool - LinkedList
structure will be good enough.
You generally need:
On top of this, you can then build whatever logging/monitoring you require.
There are also advocates for off-the-shelf connection pool frameworks. I know there are those who disagree, but I personally wouldn't go down this route-- a connection pool (a) really isn't difficult to write, (b) forms a key part of your system that you probably need to understand and customise.