文章目录
import java.util.Collection;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
public interface BlockingQueue<E> extends Queue<E> {
/**
* 1.在不违反容量限制的情况下将指定元素插入队列,成功则立即返回true。
* 2.如果没有空间则抛出IllegalStateException异常
* 3.当使用容量受限时,通常使用offer
*/
boolean add(E e);
/**
* 1.在不违反容器限制的情况下降元素插入队列,成功则返回true
* 2.如果没有可用空间则返回false
* 3.当使用容器首先是,此方法比add更可取,因为add需要抛出异常
*/
boolean offer(E e);
/**
* 将指定的元素插入队列,阻塞队列直到可用
*/
void put(E e) throws InterruptedException;
/**
* 将指定的元素插入此队列,如果需要空间,则等待指定的等待时间。
*/
boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException;
/**
* 取出队列第一个元素并删除,阻塞队列直到可用。
*/
E take() throws InterruptedException;
/**
* 取出来队列第一个元素并删除,可等待指定的等待时间以使元素变为可用。
*/
E poll(long timeout, TimeUnit unit) throws InterruptedException;
/**
* 返回此队列在理想情况下可以不阻塞的接受元素数或者(Integer.MAX_VALUE)如果没有限制
*/
int remainingCapacity();
/**
* 从队列中删除指定的元素
*/
boolean remove(Object o);
/**
* 如果此队列包含指定元素则返回true
*/
public boolean contains(Object o);
/**
* 从队列中删除所有可用元素并将它们添加到指定集合中
*/
int drainTo(Collection<? super E> c);
/**
* 从队列中删除指定数量的可用元素,并将它们添加到指定集合中
*/
int drainTo(Collection<? super E> c, int maxElements);
}