1. ArrayBlockingQueue
存
add: 抛异常
if (offer(e))
return true;
else
throw new IllegalStateException("Queue full");
put : 阻塞
while (count == items.length)
notFull.await();
offer : false
public boolean offer(E e, long timeout, TimeUnit unit) 在指定等待时间内阻塞
while (count == items.length) {
if (nanos <= 0)
return false;
nanos = notFull.awaitNanos(nanos);
}
取
poll : 没有返回null
return (count == 0) ? null : dequeue();
take : 阻塞
while (count == 0)
notEmpty.await();
peek : 返回第1个元素 没有返回null
drainTo(Collection<? super E> c, int maxElements)