@Override
    public Connection getConnection() throws SQLException {
        if (this.isClosed()) {
            throw new SQLException("Connection pool is closed");
        }
        // Immediately return if a connection is available
        Connection conn = this.waitAndGet(0);
        if (conn != null) {
            // w00t!!
            return conn;
        } else {
            // Create a new connection iff pool-capacity not exceeded.
            conn = this.createAndAdd();
            if (conn != null) {
                return conn;
            } else {
                // Wait maxWait seconds for other threads to release a connection
                long start = System.currentTimeMillis();
                conn = this.waitAndGet(this.props.getMaxWait());
                if (conn == null) {
                    if (System.currentTimeMillis() - start >= this.props.getMaxWait()) {
                        if (log.isDebugEnabled()) {
                            log.debug(this.capacityInfo("Timed out.", "\n"));
                        }
                        throw new SQLException("Timed out. No available connection after waiting for " + (this.props.getMaxWait()/1000) + " seconds.");
                    }
                }
            }
        }
        // check if pool is closed in the middle of the retrieval
        if (this.isClosed()) {
            this.disconnect(conn);
            throw new SQLException("Connection pool is closed");
        } else {
            return conn;
        }
    }