|
|
|
@ -123,7 +123,6 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
|
|
|
|
|
public T borrow(long timeout, final TimeUnit timeUnit) throws InterruptedException
|
|
|
|
|
{
|
|
|
|
|
// Try the thread-local list first
|
|
|
|
|
if (waiters.get() == 0) {
|
|
|
|
|
final List<Object> list = threadList.get();
|
|
|
|
|
for (int i = list.size() - 1; i >= 0; i--) {
|
|
|
|
|
final Object entry = list.remove(i);
|
|
|
|
@ -133,7 +132,6 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
|
|
|
|
|
return bagEntry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, scan the shared list ... then poll the handoff queue
|
|
|
|
|
final int waiting = waiters.incrementAndGet();
|
|
|
|
@ -181,7 +179,7 @@ public class ConcurrentBag<T extends IConcurrentBagEntry> implements AutoCloseab
|
|
|
|
|
{
|
|
|
|
|
bagEntry.setState(STATE_NOT_IN_USE);
|
|
|
|
|
|
|
|
|
|
while (waiters.get() > 0) {
|
|
|
|
|
while (waiters.get() > 0 && bagEntry.getState() == STATE_NOT_IN_USE) {
|
|
|
|
|
if (handoffQueue.offer(bagEntry)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|