This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Dynamic Connection Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Dynamic Connection Pool" Watch "Dynamic Connection Pool" New topic
Author

Dynamic Connection Pool

Charles Owen
Ranch Hand

Joined: Aug 31, 2009
Posts: 61
I created a ConnectionPool for a Tomcat web application and it works great. I used the Singleton pattern. It measurably improved the performance of the application. But in our enterprise, we have several environments (test-dev-production) where we connect to different databases. Is there a way of making one ConnectionPool class that could serve different databases or named connection pools? It seems with the Singleton pattern, you'd have to create a separate connection pool class for each connection pool you have configured. I hope this makes sense.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

Charles,
Did you write your own class? Using a library like dbcp means you don't have to write any classes; just ocnfigure as many connection pools as you want.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Charles Owen
Ranch Hand

Joined: Aug 31, 2009
Posts: 61
Yes, I created a custom ConnectionPool class.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

If you write your own, then yes - you would need multiple logical classes. Which could be one class with configurable parameters. For example if you call MyConnectionPool.getInstance("test") or MyConnectionPool.getInstance("prod"), it would return a singleton for that parameter. MyConnectionPool would store a map of keys to logical singletons.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Dynamic Connection Pool
 
Similar Threads
Pattern used in the qn
Question about design pattern
a question about Singleton
a mock quiz about Design Pattern
Mock Exam question