wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Singleton objects for data base connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Singleton objects for data base connection" Watch "Singleton objects for data base connection" New topic
Author

Singleton objects for data base connection

Varadhan Sesharaman
Ranch Hand

Joined: Apr 21, 2011
Posts: 30

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

Joined: Apr 30, 2005
Posts: 164
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

Joined: Oct 13, 2005
Posts: 39079
    
  23
Most people now doubt that singletons are actually good at all.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Apr 21, 2011
Posts: 30

Thanks guys
 
GeeCON Prague 2014
 
subject: Singleton objects for data base connection