- 浏览: 980227 次
文章分类
- 全部博客 (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 1244ThreadPoolExecutor解析一(核心线程池数量、线 ... -
ScheduledThreadPoolExecutor解析三(关闭线程池)
2017-04-06 20:52 4450ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析二(任务调度)
2017-04-06 12:56 2116ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析一(调度任务,任务队列)
2017-04-04 22:59 4986Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析四(线程池关闭)
2017-04-03 23:02 9096Executor接口的定义:http: ... -
ThreadPoolExecutor解析三(线程池执行提交任务)
2017-04-03 12:06 6079Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析二(线程工厂、工作线程,拒绝策略等)
2017-04-01 17:12 3036Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析一(核心线程池数量、线程池状态等)
2017-03-31 22:01 20513Executor接口的定义:http://donald-dra ... -
ScheduledExecutorService接口定义
2017-03-29 12:53 1501Executor接口的定义:http://donald-dra ... -
AbstractExecutorService解析
2017-03-29 08:27 1071Executor接口的定义:http: ... -
ExecutorCompletionService解析
2017-03-28 14:27 1586Executor接口的定义:http://donald-dra ... -
CompletionService接口定义
2017-03-28 12:39 1061Executor接口的定义:http://donald-dra ... -
FutureTask解析
2017-03-27 12:59 1324package java.util.concurrent; ... -
Future接口定义
2017-03-26 09:40 1190/* * Written by Doug Lea with ... -
ExecutorService接口定义
2017-03-25 22:14 1158Executor接口的定义:http://donald-dra ... -
Executor接口的定义
2017-03-24 23:24 1671package java.util.concurrent; ... -
简单测试线程池拒绝执行任务策略
2017-03-24 22:37 2023线程池多余任务的拒绝执行策略有四中,分别是直接丢弃任务Disc ... -
JAVA集合类简单综述
2017-03-23 22:51 920Queue接口定义:http://donald-draper. ... -
DelayQueue解析
2017-03-23 11:00 1732Queue接口定义:http://donald-draper. ... -
SynchronousQueue解析下-TransferQueue
2017-03-22 22:20 2133Queue接口定义:http://donald-draper. ...
相关推荐
`ConcurrentLinkedQueue`继承自`AbstractQueue`,这是一个抽象类,定义了一些基本的队列操作方法。同时,它实现了`Queue`接口,该接口定义了一组标准的队列操作。此外,`ConcurrentLinkedQueue`还实现了`...
ArrayBlockingQueue的继承体系中,它继承了AbstractQueue,实现了BlockingQueue接口。 ArrayBlockingQueue的主要属性包括元素数组itemArray、元素个数count和锁对象lock。ArrayBlockingQueue提供了多种构造方法,...
它们都继承自AbstractQueue类,并实现了BlockingQueue接口,提供了线程安全的队列操作。 ArrayBlockingQueue实现原理: ArrayBlockingQueue内部使用数组存储元素,使用ReentrantLock来保证线程安全,使用Condition...
1. 定义队列类:创建一个新的类,命名为IntegerQueue,继承自Java的AbstractQueue接口,这样可以自动获得部分队列操作的默认实现。 2. 内部数据结构:在IntegerQueue类中,我们需要一个数据结构来存储元素。可以...
AbstractQueue 抽象类LinkedList ArrayDeque PriorityQueue 反射的思想及作用 反射的基本使用 获取类的 Class 对象构造类的实例化对象获取-个类的所有信息 获取类中的变量(Field) 获取类中的方法(Method) 获取类的...
在Java中实现顺序队列,可以继承`AbstractQueue`或实现`Queue`接口,定义一个内部数组存储元素,并提供相应的添加、删除和查询方法。Java的自动内存管理使得开发者无需关注内存分配和释放,但需要注意并发环境下同步...
PriorityQueue是一个不阻塞的优先级队列,继承自AbstractQueue并实现了Serializable接口。它会根据元素的自然顺序或者根据构造函数提供的Comparator来排序元素。ConcurrentLinkedQueue是基于链接节点的线程安全队列...
`AbstractList`、`AbstractListModel`、`AbstractMap`、`AbstractMethodError`、`AbstractPreferences`、`AbstractQueue`、`AbstractQueuedSynchronizer`、`AbstractSelectableChannel`、`AbstractSelector`、`...
`LinkedBlockingQueue` 同样是 `java.util.concurrent` 包下的一个线程安全的阻塞队列实现,它继承自 `AbstractQueue` 并实现了 `BlockingQueue` 接口。`LinkedBlockingQueue` 的特点是可以在队列满时阻塞生产者线程...
- `java.util.AbstractQueue<E>` - `java.util.PriorityQueue<E>` #### 构造方法 - **PriorityQueue()**:使用默认的初始容量(通常是11)创建一个`PriorityQueue`,并根据元素的自然顺序进行排序。 - **...
- **`AbstractQueue`抽象类**:为`Queue`接口提供了一些基本实现。 - **`LinkedList`**(再次提到):除了可以用作列表外,还可以用作队列或栈。 - **`ArrayDeque`**:基于数组实现的双端队列,对于频繁的添加和删除...
《LMAX AbstractQueue:构建高性能交易系统的基石》 在金融交易领域,毫秒甚至微秒级别的性能差异都可能带来显著的利润变化。LMAX Disruptor,作为一个高性能、低延迟的消息处理框架,正是为了解决这类问题而设计的...
"abstractQueue.h"和"abstractStack.h"是两个头文件,它们可能定义了抽象的数据结构——队列和堆栈的接口。在C/C++编程中,使用抽象数据类型可以提供一种封装机制,隐藏内部实现细节,只对外提供必要的操作方法。这...
- PriorityQueue是Java集合框架的一部分,继承自AbstractQueue接口,并实现了Serializable和Cloneable接口。 - 它的内部实现基于二叉堆,提供了插入、删除、检查最大元素(堆顶元素)以及查找特定元素的方法。 3....
Java中的`java.util.ArrayDeque`类是一个高效且灵活的数据结构,它实现了`Deque`接口,同时也继承了`AbstractCollection`和`AbstractQueue`。`ArrayDeque`是一个基于可变数组的双端队列,它的主要特点是它使用一个...
import java.util.AbstractQueue; import java.util.Vector; import javax.swing.*; import javax.swing.table.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree....