| Author |
Singleton for datasource?
|
joseph corner
Ranch Hand
Joined: Feb 20, 2004
Posts: 50
|
|
I have a web application which uses Tomcat's connection pooling. I am paranoid about opening and closing connections efficiently. Does this approach seem reasonable? I use a singleton class to create a single datasource, then use that for opening connections: Thanks for any feedback / reassurance!
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
What advantage do you think using a singleton gives you? Your code is stil open to the problem of developers forgetting to call DbConnection.close() is a safe way, so I'm not sure what it is you are trying to achieve by wrapping the DataSource and COnnection in your own classes.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
joseph corner
Ranch Hand
Joined: Feb 20, 2004
Posts: 50
|
|
I was thinking in terms of efficiency - that it would be better to just have a single datasource object. I'm not totally clear on how Tomcat's pooling works, so this also seemed likely to ensure that there would just be one pool of connections, as they all come from the same datasource. Am I on the wrong track?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
The DataSource in Tomcat is JNDI bound is it not? In which case you probably are only using one instance anyway. So there is only going to be one connection pool. I think you might be worrying about something that is already taken care of.  [ January 23, 2007: Message edited by: Paul Sturrock ]
|
 |
 |
|
|
subject: Singleton for datasource?
|
|
|