• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connction pooling

 
kirti sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have read in a book connction pooling
i know the concept of singalon classs..
my question is why do we use connection pooling if there is already a singalton class concept...

please help me ...

thanks in advance...
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
[ October 10, 2008: Message edited by: Campbell Ritchie ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Answers.com
"The ability to open several connections to a database and distribute those connections to the next available request for data. On the Web, connection pooling is performed to improve performance. Otherwise opening a database connection for each user request adds overhead, and maintaining a connection for each user wastes resources."

Your connection pool is a singleton, not your connection. There must be multiple instance of connection objects in the pool, otherwise why need pool.
 
kirti sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as you said there will be multiple instsance of connnection objects in the pool then there will also the question of synchronisation

i am not being able to undersstand why do we use connection pooling
as there are say 2 obj in the pool there 2 users can run DML commands in the same resource in the DB ... the DB can be currupted... what you say...


as on the other had if we use a singalton class and synchronise the function the manipulate DB then at a time only one user would be able to run DML command on the db on same resourcce....then the question of DB curruption will be removed
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kirti sharma:
as you said there will be multiple instsance of connnection objects in the pool then there will also the question of synchronisation

i am not being able to undersstand why do we use connection pooling
as there are say 2 obj in the pool there 2 users can run DML commands in the same resource in the DB ... the DB can be currupted... what you say...


Not really. There are proven connection pool implementations available. The pooling frameworks are written with all these considerations, using sophisticated thread synchronization and locking mechanism. Further, there is no question of DB corruption as it has its own locking mechanism and much more sophisticated. Usual, DB used to have table level locking, row level, etc. plus they have other things like optimistic locking and pessimistic locking and stuff. Hence, the bottom line is you need not worry about all these things. Just get a connection pool framework, start using it and then you go. You might want to try writing your own pool just to get the exact concept.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

as on the other had if we use a singalton class and synchronise the function the manipulate DB then at a time only one user would be able to run DML command on the db on same resourcce....then the question of DB curruption will be removed


No offense, but it would be very naive approach. It looks like you are creating an app for a single user. If thats the case, you are good to go. Otherwise, your application will not see the light of a day.

Think about performance. It would be a nightmare, not just that it would be a daymare . No user likes to wait that long and in a web app might get a page expired error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic