A simple way to check pool members are re-used: If your JDBC vendor is using the standard toString
from Object you should see the same values printed when you print the connection:
System.out.println("Connection="+conn);
If this changes each pool get call, then the connection is not the same as before. However this may not help you at all if your DataSource is wrapping a pooled connection each time with it's own handler class - typically done to make close()
return to DataSource and keeps the underlying Connection open.
If your JDBC vendor has not used standard toString()
you can make your own string to use in debug / test statements:
public String toString(Connection conn) {
return conn.getClass().getName() + "@" + Integer.toHexString(conn.hashCode());
}
System.out.println("Connection="+toString(conn));
Note that the above approach does not guard against rogue code changing elements of the Connection
or leaving it in in-determinate state. For example I've seen: altered auto-commit modes, selecting another default database database schema (Sybase), not committing the previous transaction!
For some DBs you can mitigate with a test query before use but this incurs an overhead.