• Post Reply Bookmark Topic Watch Topic
  • New Topic

Initialize connection pool

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on to implement a connection pool (http://homepages.nildram.co.uk/~slink/java/DBPool/)

When starting up the web application the connection pool is initialized, so far so good:



When ever I want to get a connection I need access the ConnectionPoolManager object from a java class. I know I can call the pool with a unique name, but I need somehow to get access to the object without creating more instances. What is best pratice?

Do I have to share the object in a session or is it possible to access the ConnectionPoolManager object without creating a new instance?


[ November 03, 2007: Message edited by: Jeppe Fjord ]
 
Abdel Olakara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As far as I know, getConnection method returns a ideal connection. I am sure that in the returns a connection from the existing connection pool (in our case cpm Object). So you get an connection instance only and you are not creating a new connection object.
--Abdel Olakara
http://technopaper.blogspot.com
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abdel Olakara:
Hi,
As far as I know, getConnection method returns a ideal connection. I am sure that in the returns a connection from the existing connection pool (in our case cpm Object). So you get an connection instance only and you are not creating a new connection object.
--Abdel Olakara
http://technopaper.blogspot.com


Hi, but to get a connection ( cpm.getConnection() ) I need to have access to the ConnectionPoolManager object called snaq.db.ConnectionPoolManager cpm, right?

And if I make a new ConnectionPoolManager object each time the user access a page, I guess I will have several pools initialized...

So my question is, after initializing the pool at web startup, then how is it possible to share the ConnectionPoolManager object called snaq.db.ConnectionPoolManager cpm, so I can access it and i.e. get a connection from it?

Is it best practice to save it in the ServletContext or are there other ways to do it?
[ November 04, 2007: Message edited by: Jeppe Sommer ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make a static method someplace that returns the current CPM.

This looks a bit like the common Singleton, but it's not because you might want to connect to two databases at once some day. From that signature, I'd guess CPM has a static map of connection pool instances, and the map has perhaps exactly one entry as long as you have only one database.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!