Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database connection pooling datastructure

I would like to develop database connection pooling.

Could anyone please tell me about which data structure need to use to maintain the pool ?

like image 661
Isabel Jinson Avatar asked May 27 '09 10:05

Isabel Jinson


2 Answers

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:

  1. unlocked - for free objects, which can be provided to the client by request
  2. locked - for locked objects, which are in use now

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.

like image 181
Nikolay Vyahhi Avatar answered Oct 29 '22 22:10

Nikolay Vyahhi


See http://www.javaworld.com/jw-06-1998/jw-06-object-pool.html. Good luck!

like image 34
trunkc Avatar answered Oct 29 '22 22:10

trunkc