Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton objects for data base connection

 
Varadhan Sesharaman
Ranch Hand
Posts: 30
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some gave an example of creating singleton Connection object is more effcient.

How thus can be done and in what way it will be helpfull for the connection?
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singleton ensures that only one object has access to the database at a time, therefore reduces load and eliminates consistency issues between processes.
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most people now doubt that singletons are actually good at all.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varadhan Sesharaman wrote:Some gave an example of creating singleton Connection object is more effcient.


Singleton is not more efficient. Using one single Connection object for a long time instead of creating new ones that are short-lived and then created a new for every DB action can be more efficient, in the same way that it's more efficient to make one phone call to your friend and say, "Let's meet at 8:00," than to make 4 phone calls, saying, "Let's", and "meet" and "at" and "8:00."

But Singleton doesn't inherently have anything to do with that, nor does its lack.
 
Varadhan Sesharaman
Ranch Hand
Posts: 30
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic