diff --git a/client/src/com/aerospike/client/cluster/Pool.java b/client/src/com/aerospike/client/cluster/Pool.java index 1805b2e8e..1820f8e02 100644 --- a/client/src/com/aerospike/client/cluster/Pool.java +++ b/client/src/com/aerospike/client/cluster/Pool.java @@ -91,21 +91,22 @@ public Connection poll() { lock.lock(); try { - if (size == 0) { + int s = size; + if (s == 0) { return null; } - if (head == 0) { - head = conns.length - 1; - } - else { - head--; + final Connection[] conns = this.conns; + int h = head - 1; + if (h < 0) { + h = conns.length - 1; } - size--; + head = h; + s--; + size = s; - final Connection[] conns = this.conns; - final Connection conn = conns[head]; - conns[head] = null; + final Connection conn = conns[h]; + conns[h] = null; return conn; } finally {