2

In the scenario where a connection is got from a database pool(like Commons DBCP, etc) and when the connection is closed using connection.close(), how is the connection returned to the pool?

Is there come callback method in connection object which is called on connection.close() which returns the connection back to the pool from which it originated?

3
  • 1
    why do you ask? Isn't it sufficient that the connectionn is returned to the pool? Commented Jul 7, 2009 at 12:20
  • 6
    What is wrong with trying to know how things work? Commented Jul 7, 2009 at 12:23
  • 1
    because the reason people ask such question is usually because they are trying to do something which is not recommended!! But I'm sure you are not... Commented Jul 7, 2009 at 12:24

1 Answer 1

6

Usually the connection object you receive is a decorator of the original one and calling close simply returns it to the pool. It does not close it.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, that was the question and the answer is correct. The pool returns a connection that encapsulates the real one and calling close() on it simply returns the object to the pool. The underlying connection is closed by other means (pool management)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.