aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Singeton Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Singeton Question " Watch "Singeton Question " New topic
Author

Singeton Question

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
Hi All,

a dumb question, if i have a singeton pattern for database connection, is that means if i have 10 request from user, it will have single instance calling or 10 instances ?

thank you !
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Nakata kokuyo wrote:Hi All,

a dumb question, if i have a singeton pattern for database connection, is that means if i have 10 request from user, it will have single instance calling or 10 instances ?

thank you !


All 10 request will share a single database connection.


SCJP 6
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
would it be a problem if 10 request sharing a instance ? ie : request_A doing insertion whereas request_B doing updating
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Bad idea. Both the idea of the singleton and keeping the connection open forever are bad idea´s. Singletons are in no way OO and keeping the connection open forever will cause your application to crash when the DB closes the connection because it is opened too long and thus timed out.

Just acquire and close the connection in shortest possible scope. Open it right before creating the statement and close it right after closing the statement. To improve general performance, use connection pooling. If you´re running a web application on an application server, consult the appserver specific documentation how to create datasources. If you´re running a simple client application, look for connection pooling API´s like DBCP, C3P0 and Proxool.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
There is a "l" character in the name Singleton. Also, in English, the first letter of a name is capitalized, i.e. use a capital letter 'S'.

Also, the first letter of the first word in an English sentence is capitalized.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singeton Question