From e25b4ace4c123760761a02286437b8584fb6aa04 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Sun, 3 May 2015 23:54:27 +0900 Subject: [PATCH] Minor cleanup and comments. --- .../java/com/zaxxer/hikari/util/ConcurrentBag.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java b/src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java index 83d23ffc..914d3096 100644 --- a/src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java +++ b/src/main/java/com/zaxxer/hikari/util/ConcurrentBag.java @@ -90,8 +90,8 @@ public class ConcurrentBag implements AutoCloseab @SuppressWarnings("unchecked") public T borrow(long timeout, final TimeUnit timeUnit) throws InterruptedException { + // Try the thread-local list first, if there are no blocked threads waiting already if (!synchronizer.hasQueuedThreads()) { - // Try the thread-local list first final ArrayList> list = threadList.get(); if (list == null) { threadList.set(new ArrayList>(16)); @@ -111,13 +111,9 @@ public class ConcurrentBag implements AutoCloseab Future addItemFuture = null; final long startScan = System.nanoTime(); final long originTimeout = timeout; - long startSeq = 0; + long startSeq = 0; // 0 intentionally causes tryAcquireSharedNanos() to fall-thru in the first iteration try { - do { - if (!synchronizer.tryAcquireSharedNanos(startSeq, timeout)) { - break; - } - + while (timeout > 1000L && synchronizer.tryAcquireSharedNanos(startSeq, timeout)) { do { startSeq = sequence.sum(); for (final T bagEntry : sharedList) { @@ -133,7 +129,6 @@ public class ConcurrentBag implements AutoCloseab timeout = originTimeout - (System.nanoTime() - startScan); } - while (timeout > 1000L); // 1000ns is the minimum resolution on many systems } finally { synchronizer.releaseShared(1);