Yes, as Renjit suggested, you only need to create a DataSource once. Yesterday I ran into this problem. Each time in my "getConnection" method, I noticed that I did not create a new InitialContext and DataSource. I revised my Connection Manager class to have a static block of code that only creates a DataSource when the class loads for the first time (after reading the BalusC response into the correct use of the JDBC connection pool (Glassfish) )
I thought about using the old-school ServiceLocator template (see Pascal's answer in the link above), but I felt this overwhelmed my needs.
Another possibility is that you can also use @Resource annotation with injection in DataSources, but it does not work with Tomcat 7 .
source share