共同学习Java源代码-多线程与并发-BlockingQueue接口
来源:互联网 发布:淘宝网首页羽绒服女 编辑:程序博客网 时间:2024/06/09 20:11
这是阻塞队列的接口
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接口讲解完毕
- 共同学习Java源代码-多线程与并发-BlockingQueue接口
- 共同学习Java源代码-多线程与并发-Executor、ExecutorService接口
- 共同学习Java源代码-多线程与并发-Future、RunnableFuture接口
- 共同学习Java源代码-多线程与并发-CompletionService接口和ExecutorCompletionService类
- 共同学习Java源代码-多线程与并发-FutureTask类(一)
- 共同学习Java源代码-多线程与并发-FutureTask类(二)
- 共同学习Java源代码-多线程与并发-FutureTask类(三)
- 共同学习Java源代码-多线程与并发-AbstractExecutorService类(一)
- 共同学习Java源代码-多线程与并发-AbstractExecutorService类(二)
- 共同学习Java源代码-多线程与并发-AbstractExecutorService类(三)
- 共同学习Java源代码-多线程与并发-ThreadPoolExecutor类(一)
- 共同学习Java源代码-多线程与并发-ThreadPoolExecutor类(二)
- 共同学习Java源代码-多线程与并发-ThreadPoolExecutor类(三)
- 共同学习Java源代码-多线程与并发-ThreadPoolExecutor类(四)
- 共同学习Java源代码-并发与锁-Lock接口、Condition接口
- 共同学习Java源代码--数据结构--Collection接口
- 共同学习Java源代码--数据结构--List接口
- 共同学习Java源代码--数据结构--Set接口
- 数组对象的属性与方法
- CentOS 7 下配置shadowsocks
- JAVA既有值传递,也有引用传递
- 人工智能一种现代的方法 --第3章 通过搜索进行问题求解
- CommonJs, AMD/RequireJs,CMD/seajs, UMD, webpack
- 共同学习Java源代码-多线程与并发-BlockingQueue接口
- Oracle中 decode()函数
- Linux gdb调试器用法全面解析
- Loadrunner 实现随机日期
- [Android]annottation @NonNull and @interface
- 【转】Faster-R-CNN(Python).2:COCO数据集annotation内容
- 常用的Css颜色,选择困难症的老铁可以纠结一整天
- 磁盘知识
- [UESTC1804]小帆宝与数字8