• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singeton Question

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic