I must develop database connection pooling.

Could anybody please let me know about which data structure want to use to keep the pool ?

It ought to be implemented using Object Pool desing pattern. Read about this in Kircher, Michael; Prashant Jain; (2002-07-04). "Pooling Pattern". EuroPLoP 2002. Retrieved on 2007-06-09. or perhaps in Object Pool Design Pattern. Java implementation for ObjectPool and JDBCConnectionPool classes are available here.

Object Pool is generally a singleton with two collections of objects (e.g. database connections) inside:

  1. unlocked - free of charge objects, which may be presented to the customer by request
  2. locked - for locked objects, that are being used now

This collections could be implemented as Lists or HashTables or something like that else, is dependent in your needs. For straightforward ObjectPool - LinkedList structure is going to be adequate.

Rather than working on your own why don't you make use of a library like Commons DBCP that's broadly used and well examined.

You generally need:

  • some type of wrapper round the "raw" Connection objects to handle such things as once the connection was last provided, diagnostic information, possibly a cache of the prepared claims for your connection etc-- you define this to incorporate the thing you need
  • an assortment to place the bond wrappers for the reason that supports concurrent additions/removals-- any correctly synchronized list would do, but a ConcurrentLinkedQueue will be a reasonable choice
  • a method to manage allocations in the pool-- think about using the Semaphore class
  • possibly, grouping various pools togther into some "pool management class" (e.g. so that you can just call "getConnection(databaseName, readOnly)" also it would go to the appropriate pool)

On the top of the, after that you can build whatever logging/monitoring you need.

You will find also advocates for off-the-shelf connection pool frameworks. I understand you will find individuals who disagree, however i personally wouldn't go lower this route-- an association pool (a) really is not hard to write, (b) forms a vital a part of the body that you simply most likely need to comprehend and personalize.

Is definitely an free solution what you are searching for?

See Apache Database Connection Pool API

Check this out Sun Developer Tutorial: Connection Pooling:

In releases just before JDBC 2. every database session takes a new connection and login even when the previous connection and login used the same table and user account. Should you are utilizing a JDBC release just before 2. and wish to improve performance, you can cache JDBC connections rather.

Unsure it's smart to produce your personal.

I have used c3p0 connection pooling (with Hibernate) across many projects with positive results