- 浏览: 945733 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
Queue接口定义:http://donald-draper.iteye.com/blog/2363491
总结:
AbstractQueue的add,remove,element方法分别基于offer,poll,peek的实现,但是当队列为null时,抛出异常,而不是返回false或null。offer,poll,peek,并没有实现待子类扩展。清空,循环poll,直到为空。addAll为循环遍历集合元素,add到队列;
附:AbstractCollection
/* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ package java.util; /** * This class provides skeletal implementations of some {@link Queue} * operations. The implementations in this class are appropriate when * the base implementation does [i]not[/i] allow <tt>null</tt> * elements. Methods {@link #add add}, {@link #remove remove}, and * {@link #element element} are based on {@link #offer offer}, {@link * #poll poll}, and {@link #peek peek}, respectively, but throw * exceptions instead of indicating failure via <tt>false</tt> or * <tt>null</tt> returns. AbstractQueue提供了Queue的操作实现的基础。AbstractQueue可以作为不允许 元素为null时,Queue的简单实现。add,remove,element方法分别基于offer, poll,peek的实现,但是当队列为null时,抛出异常,而不是返回false或null。 * <p>A <tt>Queue</tt> implementation that extends this class must * minimally define a method {@link Queue#offer} which does not permit * insertion of <tt>null</tt> elements, along with methods {@link * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and * {@link Collection#iterator}. Typically, additional methods will be * overridden as well. If these requirements cannot be met, consider * instead subclassing {@link AbstractCollection}. * Queue的实现必须实现offer方法,并且允许插入null;peek,poll,size方法最好 重写,如果这些要求不能满足,可以用AbstractCollection代替。 * <p>This class is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. * * @since 1.5 * @author Doug Lea * @param <E> the type of elements held in this collection */ public abstract class AbstractQueue<E> extends AbstractCollection<E> implements Queue<E> { /** * Constructor for use by subclasses. */ protected AbstractQueue() { } /** * Inserts the specified element into this queue if it is possible to do so * immediately without violating capacity restrictions, returning * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt> * if no space is currently available. * * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds, * else throws an <tt>IllegalStateException</tt>. * * @param e the element to add * @return <tt>true</tt> (as specified by {@link Collection#add}) * @throws IllegalStateException if the element cannot be added at this * time due to capacity restrictions * @throws ClassCastException if the class of the specified element * prevents it from being added to this queue * @throws NullPointerException if the specified element is null and * this queue does not permit null elements * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ 添加一个元素,成功返回ture,否则抛出异常 public boolean add(E e) { if (offer(e)) return true; else throw new IllegalStateException("Queue full"); } /** * Retrieves and removes the head of this queue. This method differs * from {@link #poll poll} only in that it throws an exception if this * queue is empty. * * <p>This implementation returns the result of <tt>poll</tt> * unless the queue is empty. * * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ 消费队列头元素,有则返回元素,为null,则抛出异常 public E remove() { E x = poll(); if (x != null) return x; else throw new NoSuchElementException(); } /** * Retrieves, but does not remove, the head of this queue. This method * differs from {@link #peek peek} only in that it throws an exception if * this queue is empty. * * <p>This implementation returns the result of <tt>peek</tt> * unless the queue is empty. * * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ 检查是否有元素,有则返回元素,无则抛出异常 public E element() { E x = peek(); if (x != null) return x; else throw new NoSuchElementException(); } /** * Removes all of the elements from this queue. * The queue will be empty after this call returns. * * <p>This implementation repeatedly invokes {@link #poll poll} until it * returns <tt>null</tt>. */ 清空,循环poll,直到为空 public void clear() { while (poll() != null) ; } /** * Adds all of the elements in the specified collection to this * queue. Attempts to addAll of a queue to itself result in * <tt>IllegalArgumentException</tt>. Further, the behavior of * this operation is undefined if the specified collection is * modified while the operation is in progress. * * <p>This implementation iterates over the specified collection, * and adds each element returned by the iterator to this * queue, in turn. A runtime exception encountered while * trying to add an element (including, in particular, a * <tt>null</tt> element) may result in only some of the elements * having been successfully added when the associated exception is * thrown. * * @param c collection containing elements to be added to this queue * @return <tt>true</tt> if this queue changed as a result of the call * @throws ClassCastException if the class of an element of the specified * collection prevents it from being added to this queue * @throws NullPointerException if the specified collection contains a * null element and this queue does not permit null elements, * or if the specified collection is null * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this * queue, or if the specified collection is this queue * @throws IllegalStateException if not all the elements can be added at * this time due to insertion restrictions * @see #add(Object) */ //循环遍历集合元素,add到队列 public boolean addAll(Collection<? extends E> c) { if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); boolean modified = false; for (E e : c) if (add(e)) modified = true; return modified; } }
总结:
AbstractQueue的add,remove,element方法分别基于offer,poll,peek的实现,但是当队列为null时,抛出异常,而不是返回false或null。offer,poll,peek,并没有实现待子类扩展。清空,循环poll,直到为空。addAll为循环遍历集合元素,add到队列;
附:AbstractCollection
发表评论
-
Executors解析
2017-04-07 14:38 1188ThreadPoolExecutor解析一(核心线程池数量、线 ... -
ScheduledThreadPoolExecutor解析三(关闭线程池)
2017-04-06 20:52 4388ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析二(任务调度)
2017-04-06 12:56 2061ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析一(调度任务,任务队列)
2017-04-04 22:59 4896Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析四(线程池关闭)
2017-04-03 23:02 9010Executor接口的定义:http: ... -
ThreadPoolExecutor解析三(线程池执行提交任务)
2017-04-03 12:06 6009Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析二(线程工厂、工作线程,拒绝策略等)
2017-04-01 17:12 2968Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析一(核心线程池数量、线程池状态等)
2017-03-31 22:01 20445Executor接口的定义:http://donald-dra ... -
ScheduledExecutorService接口定义
2017-03-29 12:53 1431Executor接口的定义:http://donald-dra ... -
AbstractExecutorService解析
2017-03-29 08:27 997Executor接口的定义:http: ... -
ExecutorCompletionService解析
2017-03-28 14:27 1499Executor接口的定义:http://donald-dra ... -
CompletionService接口定义
2017-03-28 12:39 986Executor接口的定义:http://donald-dra ... -
FutureTask解析
2017-03-27 12:59 1258package java.util.concurrent; ... -
Future接口定义
2017-03-26 09:40 1114/* * Written by Doug Lea with ... -
ExecutorService接口定义
2017-03-25 22:14 1088Executor接口的定义:http://donald-dra ... -
Executor接口的定义
2017-03-24 23:24 1580package java.util.concurrent; ... -
简单测试线程池拒绝执行任务策略
2017-03-24 22:37 1944线程池多余任务的拒绝执行策略有四中,分别是直接丢弃任务Disc ... -
JAVA集合类简单综述
2017-03-23 22:51 858Queue接口定义:http://donald-draper. ... -
DelayQueue解析
2017-03-23 11:00 1660Queue接口定义:http://donald-draper. ... -
SynchronousQueue解析下-TransferQueue
2017-03-22 22:20 2074Queue接口定义:http://donald-draper. ...
相关推荐
超全Java集合框架讲解 - 超全Java集合框架讲解 - 集合框架总览 - Iterator Iterable ListIterator - Map 和 Collection 接口 - Map 集合体系详解 - HashMap ... - AbstractQueue 抽象类 - Lin
AbstractQueue 抽象类LinkedList ArrayDeque PriorityQueue 反射的思想及作用 反射的基本使用 获取类的 Class 对象构造类的实例化对象获取-个类的所有信息 获取类中的变量(Field) 获取类中的方法(Method) 获取类的...
import java.util.AbstractQueue; import java.util.Vector; import javax.swing.*; import javax.swing.table.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree....
人工智能-深度学习-tensorflow
人工智能毕业设计&课程设计
基于ssm的中小型企业财务管理录系统.zip
这个资源是一个基于Spring Boot和MySQL的洗衣店订单管理系统的完整源码。它包括了所有的源代码文件,以及一个详细的文档,可以帮助你理解和运行这个系统。这个系统的主要功能包括:用户注册和登录,下单,查看订单,修改订单,删除订单等。用户可以在系统中选择洗衣服务,然后提交订单。系统会自动计算订单的总价,并将其显示在用户的订单列表中。用户还可以查看自己的历史订单,以及每个订单的详细信息。此外,系统还包括了一个管理员模块。管理员可以查看所有的订单,以及对订单进行管理。他们可以修改订单的状态,例如将订单标记为已完成,或者取消订单。这个系统使用了Spring Boot框架,这是一个非常流行的Java开发框架,它可以帮助你快速地开发和部署应用程序。同时,系统也使用了MySQL数据库,这是一个广泛使用的关系型数据库,它可以存储大量的数据,并提供高效的查询功能。总的来说,这个资源是一个非常完整的洗衣店订单管理系统的源码,它可以帮助你理解如何使用Spring Boot和MySQL来开发一个实际的应用程序。无论你是正在学习Java编程,还是已经有一定的开发经验,都可以从这个资源中学到很多有用的知识和技能。
W9825G6KH-6I SDRAM,256Mb(32MB,16Mbx16),3.3v 动态随机存取存储器
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
人工智能毕业设计&课程设计
asp代码ASP基于web的学校新闻发布系统开发(论文+源代码+开题报告+文献综述+外文翻译)本资源系百度网盘分享地址
三菱PLC例程源码PLC 气压程式本资源系百度网盘分享地址
三菱PLC例程源码PLC通过RS485 对FR系列变频的控制本资源系百度网盘分享地址
基于ssm的学生档案管理系统.zip
这是一个基于Java语言开发的elfinder 2.x版本Web文件管理器后端设计,包含63个文件,其中主要文件类型包括49个Java源文件、3个XML文件、2个PNG图片文件、2个Markdown文档、1个gitattributes文件、1个gitignore文件、1个LICENSE文件、1个Properties文件、1个types文件和1个未知类型的文件。该项目提供了丰富的文件管理功能,包括自定义文件视图和自定义文件操作,为用户提供了高效、便捷的文件管理体验。
使用DS Client在PPT中动态展示分子三维结构
基于ssm+vue的汽车站车辆运管系统.zip
算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
DS在生物药物领域的解决方案
三菱PLC例程源码SBR废水处理本资源系百度网盘分享地址