File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Regarding Connection pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Regarding Connection pool" Watch "Regarding Connection pool" New topic
Author

Regarding Connection pool

Thanuja Vishwanath
Ranch Hand

Joined: Oct 07, 2010
Posts: 49
Hi,

The advantage of using connection pool is get the open connection......use it and return it to the pool once the request is processed so that other request acquires that connection and uses it.

I have a doubt...........

We generally acquire the connection and close it in finally like



here does it mean that we are closing that acquired connection or does it mean that we are returning it to the pool but connection is not closed?

I was told in an interview that connection should not be closed ...........i dont understand this.


Thanks,
Thanuja.
Abhishek Ralhan
Ranch Hand

Joined: Aug 01, 2010
Posts: 40

Yes, and the other advantage is:
- The overhead of opening and closing the connection is avoided, which could be a huge performance hit.

You may read below page and get some clarity:
http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html

Now coming to your doubt:

Whenever you close a connection, when connection pooling is implemented, the connection always returns to connection pool.
So, you must answer like whenever we do connection.close(), below two things can happen:
- If connection is obtained from the pool, connection is returned to the pool.
- Otherwise it is simply closed.

-Abhishek
I came to this world on a Learner's License
Thanuja Vishwanath
Ranch Hand

Joined: Oct 07, 2010
Posts: 49

Hi,

So, you must answer like whenever we do connection.close(), below two things can happen:
- If connection is obtained from the pool, connection is returned to the pool. (this is the case when connection pool is implemented?)
- Otherwise it is simply closed. (this is the case when connection pool is not implemented? is that so?)

correct me if iam wrong and also when the connection will be closed in connection pooling?. say i have 3 connections in a pool and all the request to my application uses it. now all the request has been processed. there is no more request to be processed. so my last request uses a connection and returns to the pool. now i dont have any request to process. so what will happen ie. when the connection will actually be closed.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

so what will happen ie. when the connection will actually be closed.

When the application stops.


OCUP UML fundamental and ITIL foundation
youtube channel
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
Or, if you are using a custom connection pool, there will probably be methods to purge/close/destroy the physical connections.

For Example, purgeCache in OracleConnectionCacheManager


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Avinash Pendse
Greenhorn

Joined: Oct 15, 2010
Posts: 2

i have implemented the connection pooling in my web Application (For the First time) . the application is for online application form which may active for specific days. i don't know how many user will access this form at a time. My question is it that sufficient or i have to make any modifications?

i have three classes 1]DBConnector : used for creating connection pool and makes a connection available from the pool.
2]connection : used to connect to connection pool.
3]appform : from where connection request is send to connection pool via connection class.

code snip in reverse i.e. from appform to dbconnector.




Method connectDB in connection class



connection pooling class




will this is sufficient for any no of users



regards
Avinash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Connection pool
 
Similar Threads
connection pooling issue in production environment -
Getting connection from pool?
JDBC Connection gets closed just after it is created.
Connection Pool
Database connection in hibernate