aspose file tools
The moose likes JDBC and the fly likes Singleton for datasource? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Singleton for datasource?" Watch "Singleton for datasource?" New topic
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 ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Singleton for datasource?
 
Similar Threads
PLEASE HELP !!! WEBSPHERE CONNECTION POOLING PART II
Using datasource for login bean & login page?
closing pooled connection with WS naming service(jndi)
datasource for mysql
IBM Websphere 5 Connection Pool