Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Singleton and DataSource

I'm developing a web application with Java and it needs a connection with a data base. Well administration of resources is very important. The application will be in a Tomcat 6 servlet container, and I've implemented BoneCP to manage connections (I can't use Spring).

I've read that JNDI lookup for DataSource is too much expensive and I'm thinking about creating a singleton of DataSource object, to get the JNDI resource only once, and return the same DataSource for future connections.

Question: Is it a good idea to create a DataSource only once, and get connections from the same DataSource? I don't want to get the same connection, only the same DataSource.

Thank you ;)

like image 838
juanitodread Avatar asked Jan 16 '13 16:01

juanitodread


1 Answers

Use a pooling datasource, such as is described here:

http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html

like image 129
PaulJWilliams Avatar answered Sep 30 '22 10:09

PaulJWilliams