I've got a Runnable which gets a connection from a connection pool as below and has 60 seconds to do something with the connection:
private static ConnectionPoolDataSource cpds; // MysqlConnectionPoolDataSource
public void run(){
while((System.currentTimeMillis()-created)<60000){
try(Connection conn = cpds.getPooledConnection().getConnection()){
//do something
}catch(SQLException sqle){}
}
}
When the thread dies after 60s, i've assumed the connection is returned to the pool and when a new thread is created the connection can be re-used. But when I list my network connections, the list keeps growing as more threads are created. Are connections created as above being returned to the pool correctly and if so how can I force the connections to be re-used ?