Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about Singleton

 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating a web application for an online product ordering system. You will be using data from several different databases and to reduce the load on the databases you have decided to use connection pooling. You have a ConnectionPool class and you want one pool for each database. However, you will have to connect to a variable number of databases. What pattern should you use?
Singleton
Prototype
Builder
Factory Method
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get an instance of javax.sql.DataSource from JNDI for each database. DataSource knows how to pool. Since DataSource is an interface, and the DB vendor supplies classes that implement it, is it a Prototype?
 
Sanjay Raghavan
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your example the answer would be a factory of singleton pools. Each pool can be represented by a singleton and a reference to the desired pool can be dynamically obtained via the ConnectionPoolFactory
HTH.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic