热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jucQueue接口以及其实现类

QueueBlockingQueueArrayBlockingQueue构造函数publicArrayBlockingQueue(intcapacity){this(capacit

Queue在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


BlockingQueue

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


ArrayBlockingQueue

在这里插入图片描述
构造函数

public ArrayBlockingQueue(int capacity) {this(capacity, false);}public ArrayBlockingQueue(int capacity, boolean fair) {if (capacity <&#61; 0)throw new IllegalArgumentException();this.items &#61; new Object[capacity];lock &#61; new ReentrantLock(fair);notEmpty &#61; lock.newCondition();notFull &#61; lock.newCondition();}public ArrayBlockingQueue(int capacity, boolean fair,Collection<? extends E> c) {this(capacity, fair);final ReentrantLock lock &#61; this.lock;lock.lock(); // Lock only for visibility, not mutual exclusiontry {int i &#61; 0;try {for (E e : c) {checkNotNull(e);items[i&#43;&#43;] &#61; e;}} catch (ArrayIndexOutOfBoundsException ex) {throw new IllegalArgumentException();}count &#61; i;putIndex &#61; (i &#61;&#61; capacity) ? 0 : i;} finally {lock.unlock();}}

LinkedBlockingQueue

在这里插入图片描述
构造函数

public LinkedBlockingQueue() {this(Integer.MAX_VALUE);}public LinkedBlockingQueue(int capacity) {if (capacity <&#61; 0) throw new IllegalArgumentException();this.capacity &#61; capacity;last &#61; head &#61; new Node<E>(null);}public LinkedBlockingQueue(Collection<? extends E> c) {this(Integer.MAX_VALUE);final ReentrantLock putLock &#61; this.putLock;putLock.lock(); // Never contended, but necessary for visibilitytry {int n &#61; 0;for (E e : c) {if (e &#61;&#61; null)throw new NullPointerException();if (n &#61;&#61; capacity)throw new IllegalStateException("Queue full");enqueue(new Node<E>(e));&#43;&#43;n;}count.set(n);} finally {putLock.unlock();}}

PriorityBlockingQueue

标题
构造函数

public PriorityBlockingQueue() {this(DEFAULT_INITIAL_CAPACITY, null);}public PriorityBlockingQueue(Collection<? extends E> c) {this.lock &#61; new ReentrantLock();this.notEmpty &#61; lock.newCondition();boolean heapify &#61; true; // true if not known to be in heap orderboolean screen &#61; true; // true if must screen for nullsif (c instanceof SortedSet<?>) {SortedSet<? extends E> ss &#61; (SortedSet<? extends E>) c;this.comparator &#61; (Comparator<? super E>) ss.comparator();heapify &#61; false;}else if (c instanceof PriorityBlockingQueue<?>) {PriorityBlockingQueue<? extends E> pq &#61;(PriorityBlockingQueue<? extends E>) c;this.comparator &#61; (Comparator<? super E>) pq.comparator();screen &#61; false;if (pq.getClass() &#61;&#61; PriorityBlockingQueue.class) // exact matchheapify &#61; false;}Object[] a &#61; c.toArray();int n &#61; a.length;// If c.toArray incorrectly doesn&#39;t return Object[], copy it.if (a.getClass() !&#61; Object[].class)a &#61; Arrays.copyOf(a, n, Object[].class);if (screen && (n &#61;&#61; 1 || this.comparator !&#61; null)) {for (int i &#61; 0; i < n; &#43;&#43;i)if (a[i] &#61;&#61; null)throw new NullPointerException();}this.queue &#61; a;this.size &#61; n;if (heapify)heapify();}public PriorityBlockingQueue(int initialCapacity) {this(initialCapacity, null);}public PriorityBlockingQueue(int initialCapacity,Comparator<? super E> comparator) {if (initialCapacity < 1)throw new IllegalArgumentException();this.lock &#61; new ReentrantLock();this.notEmpty &#61; lock.newCondition();this.comparator &#61; comparator;this.queue &#61; new Object[initialCapacity];}

SynchronousQueue

在这里插入图片描述

public SynchronousQueue() {this(false);}public SynchronousQueue(boolean fair) {transferer &#61; fair ? new TransferQueue<E>() : new TransferStack<E>();
}

DelayQueue

在这里插入图片描述

public DelayQueue() {}public DelayQueue(Collection<? extends E> c) {this.addAll(c);
}

LinkedTransferQueue

在这里插入图片描述

public LinkedTransferQueue() {}public LinkedTransferQueue(Collection<? extends E> c) {this();addAll(c);}

推荐阅读
author-avatar
瓜妞妹妹
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有