Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Singleton

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ,
I have created a website using Singleton pattern . It only creates 1 connection to database . Uhm , but I'm afraid of some problems . Many users use this website concurrently ,so is there any conflicts with that connection ?

Anh Vu
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - one connection can only serve one user at the same time.

Why did you decide to use a Singleton at all???
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If only allow one connection,that means all concurrent request will be queued to get the connection,and you website performance will be very low.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lucas Lee:
If only allow one connection,that means all concurrent request will be queued to get the connection,and you website performance will be very low.



Where would the queuing come from? Wouldn't the system just try to use the connection from two threads at the same time, and probably run into some kind of exception by doing so?
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a website, so I'm assuing it is a Java based web application.

Most frameworks, like Struts or Cocoon, have built in connection pooling facilities. You should take advantage of them.

Alternatively, most of the major players, such as IBM and Sun, have connection pooling facilities built into the tool. Those are the best.

Be careful with using Singleton patterns in J2EE applications. The number of classloaders, and potential classloading or clustering issues, can leave you with many instances of your singleton running.

Cheers!

-Cameron McKenzie
 
reply
    Bookmark Topic Watch Topic
  • New Topic