aspose file tools*
The moose likes JDBC and the fly likes connction pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connction pooling" Watch "connction pooling" New topic
Author

connction pooling

kirti sharma
Greenhorn

Joined: Oct 10, 2008
Posts: 6
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

Joined: Oct 13, 2005
Posts: 38334
    
  23
Welcome to JavaRanch
[ October 10, 2008: Message edited by: Campbell Ritchie ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Oct 10, 2008
Posts: 6
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 15, 2004
Posts: 2874

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connction pooling