* @return an object
* @throws InterruptedException
*/
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
for (;;) {
InternalQueue<E> internalQueue = nextQueueAlgorithm.getNextQueue();
if (internalQueue != null) {
E e = internalQueue.poll();
count--;
internalQueue.getNotFullCond().signal();
return e;
}
if (nanos <= 0)
return null;
try {
nanos = notEmpty.awaitNanos(nanos);
} catch (InterruptedException ie) {
notEmpty.signal();
throw ie;
}
}
} finally {
lock.unlock();
}
}