- 浏览: 950619 次
文章分类
- 全部博客 (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)
/* * 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; /** * A collection designed for holding elements prior to processing. * Besides basic {@link java.util.Collection Collection} operations, * queues provide additional insertion, extraction, and inspection * operations. Each of these methods exists in two forms: one throws * an exception if the operation fails, the other returns a special * value (either <tt>null</tt> or <tt>false</tt>, depending on the * operation). The latter form of the insert operation is designed * specifically for use with capacity-restricted <tt>Queue</tt> * implementations; in most implementations, insert operations cannot * fail. * Queue优先处理元素,除了Collection的基本操作之外,Queue添加了另外插入,拉取, 检查3个操作。每一种方法都有两种格式,一种操作失败,则抛出异常,另一种返回一个 特殊的值,null或false,依赖于操作。后一种形式的插入操作是用capacity-restricted Queue来实现的,在大多数的实现中,插入操作不会失败。 * <p> * <table BORDER CELLPADDING=3 CELLSPACING=1> * <tr> * <td></td> * <td ALIGN=CENTER>[i]Throws exception[/i]</td> * <td ALIGN=CENTER>[i]Returns special value[/i]</td> * </tr> * <tr> 插入,提供 * <td><b>Insert</b></td> * <td>{@link #add add(e)}</td> * <td>{@link #offer offer(e)}</td> * </tr> * <tr>移除,拉取 * <td><b>Remove</b></td> * <td>{@link #remove remove()}</td> * <td>{@link #poll poll()}</td> * </tr> * <tr>检查 * <td><b>Examine</b></td> * <td>{@link #element element()}</td> * <td>{@link #peek peek()}</td> * </tr> * </table> * * <p>Queues typically, but do not necessarily, order elements in a * FIFO (first-in-first-out) manner. Among the exceptions are * priority queues, which order elements according to a supplied * comparator, or the elements' natural ordering, and LIFO queues (or * stacks) which order the elements LIFO (last-in-first-out). * Whatever the ordering used, the [i]head[/i] of the queue is that * element which would be removed by a call to {@link #remove() } or * {@link #poll()}. In a FIFO queue, all new elements are inserted at * the [i] tail[/i] of the queue. Other kinds of queues may use * different placement rules. Every <tt>Queue</tt> implementation * must specify its ordering properties. * Queues除了非必要之外,元素的模式为FIFO。其中的一个例外是优先级队列,元素根据 比较器或者本身的顺序添加队列( LIFO queues)中。无论什么顺序,对头的元素将会 被#remove或#poll消费/移除。在先进先出队列中,所有的新元素插入到队尾,其他队列 可能会用其他的策略添加新元素。每一种队列的实现要明确排序策略。 * <p>The {@link #offer offer} method inserts an element if possible, * otherwise returning <tt>false</tt>. This differs from the {@link * java.util.Collection#add Collection.add} method, which can fail to * add an element only by throwing an unchecked exception. The * <tt>offer</tt> method is designed for use when failure is a normal, * rather than exceptional occurrence, for example, in fixed-capacity * (or "bounded") queues. * 如果可能,offer操作,插入元素时,会返回false。这个与集合类的add方法不同的时, 集合类add方法,当失败时,则抛出一个unchecked异常。offer操作设计为在一个正常模式下的失败, 而不异常发生,比如队列容量有限。 * <p>The {@link #remove()} and {@link #poll()} methods remove and * return the head of the queue. * Exactly which element is removed from the queue is a * function of the queue's ordering policy, which differs from * implementation to implementation. The <tt>remove()</tt> and * <tt>poll()</tt> methods differ only in their behavior when the * queue is empty: the <tt>remove()</tt> method throws an exception, * while the <tt>poll()</tt> method returns <tt>null</tt>. * * <p>The {@link #element()} and {@link #peek()} methods return, but do * not remove, the head of the queue. * remove和poll元素将从队列头部消费一个元素。不同的队列实现消费队列元素顺序时,可能有不同的 策略。remove和poll操作不同的时,当队列为空时,remove抛出异常 ,poll则返回null。 * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue * methods</i>, which are common in concurrent programming. These methods, * which wait for elements to appear or for space to become available, are * defined in the {@link java.util.concurrent.BlockingQueue} interface, which * extends this interface. * Queue没有定义阻塞队列的方法,这些方法会在并发编程中用到。这些方法,比如,在队列为空时, 消费者阻塞等待队列有元素可利用,这些方法在BlockingQueue接口中定义。 * <p><tt>Queue</tt> implementations generally do not allow insertion * of <tt>null</tt> elements, although some implementations, such as * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>. * Even in the implementations that permit it, <tt>null</tt> should * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also * used as a special return value by the <tt>poll</tt> method to * indicate that the queue contains no elements. 队列的实现通常不允许插入null,尽管LinkedList不禁止插入null值。即使允许插入null, 我们也利用利用poll操作,来暗示队列中没有元素。 * * <p><tt>Queue</tt> implementations generally do not define * element-based versions of methods <tt>equals</tt> and * <tt>hashCode</tt> but instead inherit the identity based versions * from class <tt>Object</tt>, because element-based equality is not * always well-defined for queues with the same elements but different * ordering properties. * Queue的实现通常不会定义equals和hashCode方法,而是继承自Object,因为hash值和值相等 ,但是顺序属性可能不同。 * * <p>This interface is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. * * @see java.util.Collection * @see LinkedList * @see PriorityQueue * @see java.util.concurrent.LinkedBlockingQueue * @see java.util.concurrent.BlockingQueue * @see java.util.concurrent.ArrayBlockingQueue * @see java.util.concurrent.LinkedBlockingQueue * @see java.util.concurrent.PriorityBlockingQueue * @since 1.5 * @author Doug Lea * @param <E> the type of elements held in this collection */ public interface Queue<E> extends Collection<E> { /** * 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. * 在有界队列未满的情况下,添加元素,返回true,没空间可利用,则抛出异常IllegalStateException * @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 */ boolean add(E e); /** * Inserts the specified element into this queue if it is possible to do * so immediately without violating capacity restrictions. * When using a capacity-restricted queue, this method is generally * preferable to {@link #add}, which can fail to insert an element only * by throwing an exception. * 在有界队列未满的情况下,添加元素,立即成功;当队列为有界是,add更好,因为越界抛出异常 * @param e the element to add * @return <tt>true</tt> if the element was added to this queue, else * <tt>false</tt> * @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 */ boolean offer(E e); /** * 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. * 从对头消费一个元素,当队列为空,抛出异常 * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ E remove(); /** * Retrieves and removes the head of this queue, * or returns <tt>null</tt> if this queue is empty. * 从对头消费一个元素,当队列为空,返回null * @return the head of this queue, or <tt>null</tt> if this queue is empty */ E poll(); /** * 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. * 检查队列中是否有元素,当队列为空,抛出异常 * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ E element(); /** * Retrieves, but does not remove, the head of this queue, * or returns <tt>null</tt> if this queue is empty. * 检查队列中是否有元素,当队列为空,返回null * @return the head of this queue, or <tt>null</tt> if this queue is empty */ E peek(); }
附:Collection
发表评论
-
Executors解析
2017-04-07 14:38 1197ThreadPoolExecutor解析一(核心线程池数量、线 ... -
ScheduledThreadPoolExecutor解析三(关闭线程池)
2017-04-06 20:52 4400ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析二(任务调度)
2017-04-06 12:56 2069ScheduledThreadPoolExecutor解析一( ... -
ScheduledThreadPoolExecutor解析一(调度任务,任务队列)
2017-04-04 22:59 4909Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析四(线程池关闭)
2017-04-03 23:02 9025Executor接口的定义:http: ... -
ThreadPoolExecutor解析三(线程池执行提交任务)
2017-04-03 12:06 6020Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析二(线程工厂、工作线程,拒绝策略等)
2017-04-01 17:12 2983Executor接口的定义:http://donald-dra ... -
ThreadPoolExecutor解析一(核心线程池数量、线程池状态等)
2017-03-31 22:01 20458Executor接口的定义:http://donald-dra ... -
ScheduledExecutorService接口定义
2017-03-29 12:53 1444Executor接口的定义:http://donald-dra ... -
AbstractExecutorService解析
2017-03-29 08:27 1010Executor接口的定义:http: ... -
ExecutorCompletionService解析
2017-03-28 14:27 1513Executor接口的定义:http://donald-dra ... -
CompletionService接口定义
2017-03-28 12:39 997Executor接口的定义:http://donald-dra ... -
FutureTask解析
2017-03-27 12:59 1269package java.util.concurrent; ... -
Future接口定义
2017-03-26 09:40 1124/* * Written by Doug Lea with ... -
ExecutorService接口定义
2017-03-25 22:14 1106Executor接口的定义:http://donald-dra ... -
Executor接口的定义
2017-03-24 23:24 1590package java.util.concurrent; ... -
简单测试线程池拒绝执行任务策略
2017-03-24 22:37 1955线程池多余任务的拒绝执行策略有四中,分别是直接丢弃任务Disc ... -
JAVA集合类简单综述
2017-03-23 22:51 869Queue接口定义:http://donald-draper. ... -
DelayQueue解析
2017-03-23 11:00 1672Queue接口定义:http://donald-draper. ... -
SynchronousQueue解析下-TransferQueue
2017-03-22 22:20 2082Queue接口定义:http://donald-draper. ...
相关推荐
文章目录简介Queue接口Queue的分类BlockingQueueDequeTransferQueue总结 java中Queue家族简介 简介 java中Collection集合有三大家族List,Set和Queue。当然Map也算是一种集合类,但Map并不继承Collection接口。 List...
主要介绍Queue的相关知识,包括Queue的定义,发送和接收消息的方式等内容。重点使用Free RTOS中Queue的接口,实现数据在不同task之间的发送和接收的案例,并在板卡上验证该功能。
(完整项目,可直接食用)Java提供的java.util.Queue是一个接口没有构造函数。试用java.util.Stack泛型栈作为父类,用另一...除提供无参构造函数Queue( )外,其它所有队列函数严格参照java.util.Queue的接口定义实现。
Collection接口是List、Set和Queue接口的父接口,定义了存取一组对象的方法。Collection接口继承自Iterable接口,这意味着可以通过for-each循环遍历集合元素。 List接口是有序的集合,可以包含重复的元素。List接口...
为了将此应用程序安装到您本地的 ArangoDB,您可以像这样使用 Foxx-manager foxx-manager install queue-it /queue这会将应用程序下载到 ArangoDB 的本地安装(必须已启动并运行)并将其安装在路径“/queue”下。...
PHP JobQueue组件 简单的Job / Queue PHP组件,可帮助应用程序通过多个工作程序分发任务。安装该软件包可通过Composer安装并自动加载: $ ... 必须在实现ExecutableJob接口PHP类中定义每个作业: <?phpuse JobQ
[问题描述] 设停车厂只有一个可停放几辆汽车的狭长通道,且只有—个大门可供汽车进出。汽车在停车场内按车辆到达的先后顺序依次排列,若...3.定义Queue接口 4.设计等待队列WaitQueue 5.定义结点类Node 6.搭建管理界面
9. 使用Java集合类实现队列:演示了如何使用Java集合类中的Queue接口来实现队列数据结构。 10. 多线程编程:创建和启动线程:展示了如何通过实现Runnable接口创建一个新线程,并演示了多线程编程的基本概念。
一般我们比较少接触MessageQueue, 其实它内部的IdleHandler接口有很多有趣的用法,首先看看它的定义: 简而言之,就是在looper里面的message暂时处理完了,这个时候会回调这个接口,返回false,那么就会移除它,...
定义IRPC接口用来处理同步调用的被调用端 定义Bind函数用来绑定IRPC接口的实例 定义CallEx函数用来实现用户同步调用 2.3 添加bInit变量,用于设置初始化和关闭状态。 设置此变量的目的主要是用来控制,在关闭了...
msqueue_config_loader 定义消息队列配置结构并实现LoadByFile和LoadByBytes接口。 type QueueConfig struct {Url string `json:"url" yaml:"url"`AccessKeyId string `json:"access_key_id" yaml:"access_key_id"`...
优先队列(priority_queue)和一般队列(queue)的函数接口一致,不同的是,优先队列每次出列的是整个队列中最小(或者最大)的元素。 本文简要介绍一种基于数组二叉堆实现的优先队列,定义的数据结构和实现的函数接口...
简单地说就是一种接口类,专门用来修改现有类的接口,提供一种新的接口;或调用现有的函数来实现所需要的功能。 主要包括3种适配器Container Adaptors、Iterator Adaptors与Function Adaptors。其中迭代器适配器...
Notification发送者可以自己定义设置发送的Queue,自己灵活处理阻塞,超时等问题。 Example: 更多的例子在src/test/java 目录下。 public class MainExample { public static void main...
16.2.7 队列集合:Queue 455 16.2.8 链表:LinkedList 456 16.3 提供索引器 456 16.4 返回null或者空集合 459 16.5 迭代器 459 16.5.1 迭代器的定义 460 16.5.2 迭代器语法 460 16.5.3 ...
Foundatio提供了一下不同的方法来定义一个Job。1、Jobs:提供了一、IJob 接口,和一个默认的基类JobBase。直接上代码吧:using Foundatio.Jobs; public class HelloWorldJob : JobBase { public int ...
第13章 创建接口和定义抽象类 227 13.1 理解接口 227 13.1.1 定义接口 228 13.1.2 实现接口 228 13.1.3 通过接口来引用一个类 230 13.1.4 使用多个接口 230 13.1.5 显式实现接口 230 13.1.6 接口的限制 232 ...
线路速率大于接口能力 1) 使用hold-queue减少进入的队列尺寸2) 增加输出的队列尺寸 接口速率大于线路速率 1) 减少广播流量2) 增加输出的队列3) 如有需要,使用队列算法 二、处理帧中继故障 DLCI用于在...
线路速率大于接口能力 1) 使用hold-queue减少进入的队列尺寸2) 增加输出的队列尺寸 接口速率大于线路速率 1) 减少广播流量2) 增加输出的队列3) 如有需要,使用队列算法 二、处理帧中继故障 DLCI用于在...