共同学习Java源代码-多线程与并发-BlockingQueue接口

这是阻塞队列的接口 

public interface BlockingQueue<E> extends Queue<E>

继承自Queue接口


    boolean add(E e);

添加元素方法 长度超出了会抛异常


    boolean offer(E e);

添加元素的另一种方法 添加失败就返回false 官方更建议用这个


    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;

将队列头部元素取出的方法 在时限内会阻塞线程


    int remainingCapacity();

计算剩余容量的方法


    boolean remove(Object o);

删除元素方法


public boolean contains(Object o);

判断元素是否存在的方法


    int drainTo(Collection<? super E> c);

将本队列所有元素清空 并将所有元素放入参数Collection方法


将本队列中指定数目的元素清空 并放入参数Collection的方法

int drainTo(Collection<? super E> c, int maxElements);


BlockingQueue接口讲解完毕

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值