public RRDCommand getConnection() throws Exception {
        if (finished) throw new Exception("Already finished");
        RRDPoolMember member = null;

        synchronized (this) {
            while (true) {
                for (int i = 0; i < poolsize; i++) {
                    if (pool[i] == null) {
                        pool[i] = new RRDPoolMember();
                        member = pool[i];
                        break;
                    } else if (!pool[i].inuse) {
                        member = pool[i];
                        break;
                    }
                }
                if (member != null) {
                    member.inuse = true;
                    break;
                } else {
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        // 		ignore
                    }
                    // next loop iteration
                }
            }
        }

        member.requestcount++;
        if (member.rrdp == null) {
            member.requestcount = 0;
            member.rrdp = factory.createRRDCommand();
        }

        return new RRDPoolMemberWrapper(member);
    }