You are not actually using a connection pool. A ConnectionPoolDataSource
isn't intended to be used directly. It is intended as a (special) DataSource
for PooledConnection
objects which are then kept in a connection pool by a (normal) DataSource
implementation that provides connection pooling.
A normal developer should not use a ConnectionPoolDataSource
directly, it is intended for use with connection pools provided by Application Servers, or to be wrapped into general purpose DataSource
s that provided connection pooling.
When a Connection
is requested from the connection pool, it will checkout an existing PooledConnection
(or request a new one from its ConnectionPoolDataSource
), retrieve a Connection
and return that to the user. When the user closes the Connection
, the PooledConnection
will signal the connection pool that it is available again.
In this case you are creating a PooledConnection
, retrieving a Connection
from it and then discarding the PooledConnection
. This means that the PooledConnection
gets abandoned, and its physical connection to the database cannot be reused and will be closed/discarded when it is finally garbage collected (normally when the connection pool wants to close the physical connection, it will call close()
on the PooledConnection
).
You either need to use connection pooling as provided by your Application Server, or use a general purpose connection pool like DBCP, c3p0 or BoneCP.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…