• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Singeton Question

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic