I found that c3p0 connection pooling Everytime creating new object for connection for example suppose I have pool of 5 connection and when I getting a connections from pool after using that close that connections then again getting connections each time getting new hash code then how we can say that it is connection pooling ..if every time pool create a new connection then how pool comes to know that particular connection is closed??
1 Answers
The connection you get from the connection pool is - usually - a wrapper (proxy) around the physical connection, this is also the approach used by c3p0. This is to isolate the actual physical connection from its user, and it allows to intercept the close operation to return the connection to the pool. In addition, this wrapper protects the physical connection (and other parts of your application) from misbehaving code by behaving as a closed connection. For example code attempting to continue to use the connection after closing it, which could lead to hard to diagnose race conditions or other weird behavior, will instead get a connection closed error.
So it is expected that the connection you get from the pool has a different identity each time, because it is actually a new 'logical' connection every time; it just happens to reuse (wrap) a physical connection from the pool.

- 100,966
- 191
- 140
- 197
-
That means Everytime when colse method called on connection new connection created by pool to fill the place of close connection am I right?? – user3497147 Jun 30 '17 at 11:21
-
@user3497147 No. When your code calls `close()` on the connection (which is a wrapper, not the physical connection to the database!), this wrapper will start to behave as a closed connection, while at the same time the underlying physical connection will be returned to the connection pool for reuse. – Mark Rotteveel Jun 30 '17 at 11:23
-
Where these physical connection lying in which pool in which reference bean ?? – user3497147 Jun 30 '17 at 14:18
-
Sorry, I don't understand what you're asking. – Mark Rotteveel Jun 30 '17 at 14:38