If you are using DBCP2, then you can print the active connections which are not closed.
Here the class is extending BasicDataSource, and overriding getConnection method.
try {String className = Thread.currentThread().getStackTrace()[2].getClassName();
LOG.info("For class :: " + className + " || " + "max total connections :: " + super.getMaxTotal()+ " || " +" Active Connections count :: "+ super.getNumActive());
connection = super.getConnection();
}catch (SQLException e) {
LOG.error("SQL Exception in Connection", e);
}