You are not actually using a connection pool. A ConnectionPoolDataSource not intended for direct use. It is intended as a (special) DataSource for PooledConnection objects, which are then stored in the connection pool using a (regular) DataSource implementation that provides pooling.
A typical developer should not use ConnectionPoolDataSource directly; it is intended for use with connection pools provided by application servers, or for wrapping in a common DataSource that provides pooling.
When Connection is requested in the connection pool, it checks for an existing PooledConnection (or requests a new one from its ConnectionPoolDataSource ), retrieves the Connection and returns it to the user. When the user closes Connection , PooledConnection will signal the connection pool, which he will be available again.
In this case, you create a PooledConnection , extract the Connection from it, and then drop the PooledConnection . This means that the PooledConnection is denied, and its physical connection to the database cannot be reused and will be closed / dropped when it finally collects garbage (usually when the connection pool wants to close the physical connection, it calls close() on PooledConnection ) .
You need to either use the connection pool as provided by your application server, or use a common connection pool, such as DBCP, c3p0 or BoneCP.
source share