Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7bf1893e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7bf1893e
编写于
7月 03, 2013
作者:
P
psandoz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8011427: java.util.concurrent collection Spliterator implementations
Reviewed-by: martin Contributed-by:
N
Doug Lea
<
dl@cs.oswego.edu
>
上级
2bfa31ee
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
3215 addition
and
1349 deletion
+3215
-1349
src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
...hare/classes/java/util/concurrent/ArrayBlockingQueue.java
+752
-159
src/share/classes/java/util/concurrent/BlockingDeque.java
src/share/classes/java/util/concurrent/BlockingDeque.java
+61
-58
src/share/classes/java/util/concurrent/BlockingQueue.java
src/share/classes/java/util/concurrent/BlockingQueue.java
+50
-49
src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
...e/classes/java/util/concurrent/ConcurrentLinkedDeque.java
+115
-3
src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
...e/classes/java/util/concurrent/ConcurrentLinkedQueue.java
+95
-2
src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
...e/classes/java/util/concurrent/ConcurrentSkipListMap.java
+1059
-611
src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
...e/classes/java/util/concurrent/ConcurrentSkipListSet.java
+58
-40
src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
...re/classes/java/util/concurrent/CopyOnWriteArrayList.java
+388
-266
src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
...are/classes/java/util/concurrent/CopyOnWriteArraySet.java
+61
-34
src/share/classes/java/util/concurrent/DelayQueue.java
src/share/classes/java/util/concurrent/DelayQueue.java
+77
-62
src/share/classes/java/util/concurrent/Delayed.java
src/share/classes/java/util/concurrent/Delayed.java
+2
-2
src/share/classes/java/util/concurrent/LinkedBlockingDeque.java
...are/classes/java/util/concurrent/LinkedBlockingDeque.java
+132
-9
src/share/classes/java/util/concurrent/LinkedBlockingQueue.java
...are/classes/java/util/concurrent/LinkedBlockingQueue.java
+126
-4
src/share/classes/java/util/concurrent/LinkedTransferQueue.java
...are/classes/java/util/concurrent/LinkedTransferQueue.java
+113
-1
src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
...e/classes/java/util/concurrent/PriorityBlockingQueue.java
+75
-2
src/share/classes/java/util/concurrent/SynchronousQueue.java
src/share/classes/java/util/concurrent/SynchronousQueue.java
+51
-47
未找到文件。
src/share/classes/java/util/concurrent/ArrayBlockingQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/BlockingDeque.java
浏览文件 @
7bf1893e
...
...
@@ -41,17 +41,18 @@ import java.util.*;
* for the deque to become non-empty when retrieving an element, and wait for
* space to become available in the deque when storing an element.
*
* <p>
<tt>BlockingDeque</tt>
methods come in four forms, with different ways
* <p>
{@code BlockingDeque}
methods come in four forms, with different ways
* of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future:
* one throws an exception, the second returns a special value (either
*
<tt>null</tt> or <tt>false</tt>
, depending on the operation), the third
*
{@code null} or {@code false}
, depending on the operation), the third
* blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingDeque methods</caption>
* <tr>
* <td ALIGN=CENTER COLSPAN = 5> <b>First Element (Head)</b></td>
* </tr>
...
...
@@ -116,20 +117,21 @@ import java.util.*;
* </tr>
* </table>
*
* <p>Like any {@link BlockingQueue}, a
<tt>BlockingDeque</tt>
is thread safe,
* <p>Like any {@link BlockingQueue}, a
{@code BlockingDeque}
is thread safe,
* does not permit null elements, and may (or may not) be
* capacity-constrained.
*
* <p>A
<tt>BlockingDeque</tt>
implementation may be used directly as a FIFO
*
<tt>BlockingQueue</tt>
. The methods inherited from the
*
<tt>BlockingQueue</tt>
interface are precisely equivalent to
*
<tt>BlockingDeque</tt>
methods as indicated in the following table:
* <p>A
{@code BlockingDeque}
implementation may be used directly as a FIFO
*
{@code BlockingQueue}
. The methods inherited from the
*
{@code BlockingQueue}
interface are precisely equivalent to
*
{@code BlockingDeque}
methods as indicated in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Comparison of BlockingQueue and BlockingDeque methods</caption>
* <tr>
* <td ALIGN=CENTER> <b>
<tt>BlockingQueue</tt>
Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent
<tt>BlockingDeque</tt>
Method</b></td>
* <td ALIGN=CENTER> <b>
{@code BlockingQueue}
Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent
{@code BlockingDeque}
Method</b></td>
* </tr>
* <tr>
* <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
...
...
@@ -208,7 +210,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions,
* throwing an
<tt>IllegalStateException</tt>
if no space is currently
* throwing an
{@code IllegalStateException}
if no space is currently
* available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerFirst(Object) offerFirst}.
*
...
...
@@ -223,7 +225,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions,
* throwing an
<tt>IllegalStateException</tt>
if no space is currently
* throwing an
{@code IllegalStateException}
if no space is currently
* available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerLast(Object) offerLast}.
*
...
...
@@ -238,7 +240,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions,
* returning
<tt>true</tt> upon success and <tt>false</tt>
if no space is
* returning
{@code true} upon success and {@code false}
if no space is
* currently available.
* When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addFirst(Object) addFirst} method, which can
...
...
@@ -254,7 +256,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions,
* returning
<tt>true</tt> upon success and <tt>false</tt>
if no space is
* returning
{@code true} upon success and {@code false}
if no space is
* currently available.
* When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addLast(Object) addLast} method, which can
...
...
@@ -302,10 +304,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -324,10 +326,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -363,10 +365,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the head of this deque, or
<tt>null</tt>
if the specified
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the head of this deque, or
{@code null}
if the specified
* waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -379,10 +381,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the tail of this deque, or
<tt>null</tt>
if the specified
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the tail of this deque, or
{@code null}
if the specified
* waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -392,13 +394,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the first element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* @param o element to be removed from this deque, if present
* @return
<tt>true</tt>
if an element was removed as a result of this call
* @return
{@code true}
if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -410,13 +412,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Removes the last occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the last element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the last element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* @param o element to be removed from this deque, if present
* @return
<tt>true</tt>
if an element was removed as a result of this call
* @return
{@code true}
if an element was removed as a result of this call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -431,8 +433,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) 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.
*
{@code true}
upon success and throwing an
*
{@code IllegalStateException}
if no space is currently available.
* When using a capacity-restricted deque, it is generally preferable to
* use {@link #offer(Object) offer}.
*
...
...
@@ -452,7 +454,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque
* (in other words, at the tail of this deque) if it is possible to do so
* immediately without violating capacity restrictions, returning
*
<tt>true</tt> upon success and <tt>false</tt>
if no space is currently
*
{@code true} upon success and {@code false}
if no space is currently
* available. When using a capacity-restricted deque, this method is
* generally preferable to the {@link #add} method, which can fail to
* insert an element only by throwing an exception.
...
...
@@ -494,8 +496,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* {@link #offerLast(Object,long,TimeUnit) offerLast}.
*
* @param e the element to add
* @return
<tt>true</tt>
if the element was added to this deque, else
*
<tt>false</tt>
* @return
{@code true}
if the element was added to this deque, else
*
{@code false}
* @throws InterruptedException {@inheritDoc}
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this deque
...
...
@@ -522,11 +524,11 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Retrieves and removes the head of the queue represented by this deque
* (in other words, the first element of this deque), or returns
*
<tt>null</tt>
if this deque is empty.
*
{@code null}
if this deque is empty.
*
* <p>This method is equivalent to {@link #pollFirst()}.
*
* @return the head of this deque, or
<tt>null</tt>
if this deque is empty
* @return the head of this deque, or
{@code null}
if this deque is empty
*/
E
poll
();
...
...
@@ -550,7 +552,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* <p>This method is equivalent to
* {@link #pollFirst(long,TimeUnit) pollFirst}.
*
* @return the head of this deque, or
<tt>null</tt>
if the
* @return the head of this deque, or
{@code null}
if the
* specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -573,27 +575,27 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/**
* Retrieves, but does not remove, the head of the queue represented by
* this deque (in other words, the first element of this deque), or
* returns
<tt>null</tt>
if this deque is empty.
* returns
{@code null}
if this deque is empty.
*
* <p>This method is equivalent to {@link #peekFirst() peekFirst}.
*
* @return the head of this deque, or
<tt>null</tt>
if this deque is empty
* @return the head of this deque, or
{@code null}
if this deque is empty
*/
E
peek
();
/**
* Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged.
* More formally, removes the first element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
(if such an element exists).
* Returns
<tt>true</tt>
if this deque contained the specified element
* More formally, removes the first element
{@code e}
such that
*
{@code o.equals(e)}
(if such an element exists).
* Returns
{@code true}
if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call).
*
* <p>This method is equivalent to
* {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
*
* @param o element to be removed from this deque, if present
* @return
<tt>true</tt>
if this deque changed as a result of the call
* @return
{@code true}
if this deque changed as a result of the call
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -603,12 +605,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
boolean
remove
(
Object
o
);
/**
* Returns
<tt>true</tt>
if this deque contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this deque contains
* at least one element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this deque contains the specified element.
* More formally, returns
{@code true}
if and only if this deque contains
* at least one element
{@code e} such that {@code o.equals(e)}
.
*
* @param o object to be checked for containment in this deque
* @return
<tt>true</tt>
if this deque contains the specified element
* @return
{@code true}
if this deque contains the specified element
* @throws ClassCastException if the class of the specified element
* is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -635,9 +637,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
// *** Stack methods ***
/**
* Pushes an element onto the stack represented by this deque. In other
* words, inserts the element at the front of this deque unless it would
* violate capacity restrictions.
* Pushes an element onto the stack represented by this deque (in other
* words, at the head of this deque) if it is possible to do so
* immediately without violating capacity restrictions, throwing an
* {@code IllegalStateException} if no space is currently available.
*
* <p>This method is equivalent to {@link #addFirst(Object) addFirst}.
*
...
...
src/share/classes/java/util/concurrent/BlockingQueue.java
浏览文件 @
7bf1893e
...
...
@@ -44,17 +44,18 @@ import java.util.Queue;
* element, and wait for space to become available in the queue when
* storing an element.
*
* <p>
<tt>BlockingQueue</tt>
methods come in four forms, with different ways
* <p>
{@code BlockingQueue}
methods come in four forms, with different ways
* of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future:
* one throws an exception, the second returns a special value (either
*
<tt>null</tt> or <tt>false</tt>
, depending on the operation), the third
*
{@code null} or {@code false}
, depending on the operation), the third
* blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table:
*
* <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of BlockingQueue methods</caption>
* <tr>
* <td></td>
* <td ALIGN=CENTER><em>Throws exception</em></td>
...
...
@@ -85,37 +86,37 @@ import java.util.Queue;
* </tr>
* </table>
*
* <p>A
<tt>BlockingQueue</tt> does not accept <tt>null</tt>
elements.
* Implementations throw
<tt>NullPointerException</tt>
on attempts
* to
<tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>
. A
*
<tt>null</tt>
is used as a sentinel value to indicate failure of
*
<tt>poll</tt>
operations.
* <p>A
{@code BlockingQueue} does not accept {@code null}
elements.
* Implementations throw
{@code NullPointerException}
on attempts
* to
{@code add}, {@code put} or {@code offer} a {@code null}
. A
*
{@code null}
is used as a sentinel value to indicate failure of
*
{@code poll}
operations.
*
* <p>A
<tt>BlockingQueue</tt>
may be capacity bounded. At any given
* time it may have a
<tt>remainingCapacity</tt>
beyond which no
* additional elements can be
<tt>put</tt>
without blocking.
* A
<tt>BlockingQueue</tt>
without any intrinsic capacity constraints always
* reports a remaining capacity of
<tt>Integer.MAX_VALUE</tt>
.
* <p>A
{@code BlockingQueue}
may be capacity bounded. At any given
* time it may have a
{@code remainingCapacity}
beyond which no
* additional elements can be
{@code put}
without blocking.
* A
{@code BlockingQueue}
without any intrinsic capacity constraints always
* reports a remaining capacity of
{@code Integer.MAX_VALUE}
.
*
* <p>
<tt>BlockingQueue</tt>
implementations are designed to be used
* <p>
{@code BlockingQueue}
implementations are designed to be used
* primarily for producer-consumer queues, but additionally support
* the {@link java.util.Collection} interface. So, for example, it is
* possible to remove an arbitrary element from a queue using
*
<tt>remove(x)</tt>
. However, such operations are in general
*
{@code remove(x)}
. However, such operations are in general
* <em>not</em> performed very efficiently, and are intended for only
* occasional use, such as when a queued message is cancelled.
*
* <p>
<tt>BlockingQueue</tt>
implementations are thread-safe. All
* <p>
{@code BlockingQueue}
implementations are thread-safe. All
* queuing methods achieve their effects atomically using internal
* locks or other forms of concurrency control. However, the
* <em>bulk</em> Collection operations
<tt>addAll</tt>
,
*
<tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt>
are
* <em>bulk</em> Collection operations
{@code addAll}
,
*
{@code containsAll}, {@code retainAll} and {@code removeAll}
are
* <em>not</em> necessarily performed atomically unless specified
* otherwise in an implementation. So it is possible, for example, for
*
<tt>addAll(c)</tt>
to fail (throwing an exception) after adding
* only some of the elements in
<tt>c</tt>
.
*
{@code addAll(c)}
to fail (throwing an exception) after adding
* only some of the elements in
{@code c}
.
*
* <p>A
<tt>BlockingQueue</tt>
does <em>not</em> intrinsically support
* <p>A
{@code BlockingQueue}
does <em>not</em> intrinsically support
* any kind of "close" or "shutdown" operation to
* indicate that no more items will be added. The needs and usage of
* such features tend to be implementation-dependent. For example, a
...
...
@@ -125,7 +126,7 @@ import java.util.Queue;
*
* <p>
* Usage example, based on a typical producer-consumer scenario.
* Note that a
<tt>BlockingQueue</tt>
can safely be used with multiple
* Note that a
{@code BlockingQueue}
can safely be used with multiple
* producers and multiple consumers.
* <pre> {@code
* class Producer implements Runnable {
...
...
@@ -181,13 +182,13 @@ public interface BlockingQueue<E> extends Queue<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.
*
{@code true}
upon success and throwing an
*
{@code IllegalStateException}
if no space is currently available.
* When using a capacity-restricted queue, it is generally preferable to
* use {@link #offer(Object) offer}.
*
* @param e the element to add
* @return
<tt>true</tt>
(as specified by {@link Collection#add})
* @return
{@code true}
(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
...
...
@@ -201,14 +202,14 @@ public interface BlockingQueue<E> extends Queue<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 <tt>false</tt>
if no space is currently
*
{@code true} upon success and {@code false}
if no space is currently
* available. 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.
*
* @param e the element to add
* @return
<tt>true</tt>
if the element was added to this queue, else
*
<tt>false</tt>
* @return
{@code true}
if the element was added to this queue, else
*
{@code false}
* @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
...
...
@@ -237,10 +238,10 @@ public interface BlockingQueue<E> extends Queue<E> {
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return
<tt>true</tt> if successful, or <tt>false</tt>
if
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return
{@code true} if successful, or {@code false}
if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
...
...
@@ -266,10 +267,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* specified wait time if necessary for an element to become available.
*
* @param timeout how long to wait before giving up, in units of
*
<tt>unit</tt>
* @param unit a
<tt>TimeUnit</tt>
determining how to interpret the
*
<tt>timeout</tt>
parameter
* @return the head of this queue, or
<tt>null</tt>
if the
*
{@code unit}
* @param unit a
{@code TimeUnit}
determining how to interpret the
*
{@code timeout}
parameter
* @return the head of this queue, or
{@code null}
if the
* specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting
*/
...
...
@@ -279,11 +280,11 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Returns the number of additional elements that this queue can ideally
* (in the absence of memory or resource constraints) accept without
* blocking, or
<tt>Integer.MAX_VALUE</tt>
if there is no intrinsic
* blocking, or
{@code Integer.MAX_VALUE}
if there is no intrinsic
* limit.
*
* <p>Note that you <em>cannot</em> always tell if an attempt to insert
* an element will succeed by inspecting
<tt>remainingCapacity</tt>
* an element will succeed by inspecting
{@code remainingCapacity}
* because it may be the case that another thread is about to
* insert or remove an element.
*
...
...
@@ -293,14 +294,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/**
* Removes a single instance of the specified element from this queue,
* if it is present. More formally, removes an element
<tt>e</tt>
such
* that
<tt>o.equals(e)</tt>
, if this queue contains one or more such
* if it is present. More formally, removes an element
{@code e}
such
* that
{@code o.equals(e)}
, if this queue contains one or more such
* elements.
* Returns
<tt>true</tt>
if this queue contained the specified element
* Returns
{@code true}
if this queue contained the specified element
* (or equivalently, if this queue changed as a result of the call).
*
* @param o element to be removed from this queue, if present
* @return
<tt>true</tt>
if this queue changed as a result of the call
* @return
{@code true}
if this queue changed as a result of the call
* @throws ClassCastException if the class of the specified element
* is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -310,12 +311,12 @@ public interface BlockingQueue<E> extends Queue<E> {
boolean
remove
(
Object
o
);
/**
* Returns
<tt>true</tt>
if this queue contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this queue contains
* at least one element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this queue contains the specified element.
* More formally, returns
{@code true}
if and only if this queue contains
* at least one element
{@code e} such that {@code o.equals(e)}
.
*
* @param o object to be checked for containment in this queue
* @return
<tt>true</tt>
if this queue contains the specified element
* @return
{@code true}
if this queue contains the specified element
* @throws ClassCastException if the class of the specified element
* is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>)
...
...
@@ -329,10 +330,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* to the given collection. This operation may be more
* efficient than repeatedly polling this queue. A failure
* encountered while attempting to add elements to
* collection
<tt>c</tt>
may result in elements being in neither,
* collection
{@code c}
may result in elements being in neither,
* either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in
*
<tt>IllegalArgumentException</tt>
. Further, the behavior of
*
{@code IllegalArgumentException}
. Further, the behavior of
* this operation is undefined if the specified collection is
* modified while the operation is in progress.
*
...
...
@@ -353,10 +354,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* Removes at most the given number of available elements from
* this queue and adds them to the given collection. A failure
* encountered while attempting to add elements to
* collection
<tt>c</tt>
may result in elements being in neither,
* collection
{@code c}
may result in elements being in neither,
* either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in
*
<tt>IllegalArgumentException</tt>
. Further, the behavior of
*
{@code IllegalArgumentException}
. Further, the behavior of
* this operation is undefined if the specified collection is
* modified while the operation is in progress.
*
...
...
src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
浏览文件 @
7bf1893e
...
...
@@ -42,6 +42,9 @@ import java.util.Deque;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
import
java.util.Queue
;
import
java.util.Spliterator
;
import
java.util.Spliterators
;
import
java.util.function.Consumer
;
/**
* An unbounded concurrent {@linkplain Deque deque} based on linked nodes.
...
...
@@ -816,7 +819,7 @@ public class ConcurrentLinkedDeque<E>
* Creates an array list and fills it with elements of this list.
* Used by toArray.
*
* @return the array
L
ist
* @return the array
l
ist
*/
private
ArrayList
<
E
>
toArrayList
()
{
ArrayList
<
E
>
list
=
new
ArrayList
<
E
>();
...
...
@@ -1024,11 +1027,27 @@ public class ConcurrentLinkedDeque<E>
}
public
E
poll
()
{
return
pollFirst
();
}
public
E
remove
()
{
return
removeFirst
();
}
public
E
peek
()
{
return
peekFirst
();
}
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public
E
remove
()
{
return
removeFirst
();
}
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public
E
pop
()
{
return
removeFirst
();
}
/**
* @throws NoSuchElementException {@inheritDoc}
*/
public
E
element
()
{
return
getFirst
();
}
/**
* @throws NullPointerException {@inheritDoc}
*/
public
void
push
(
E
e
)
{
addFirst
(
e
);
}
public
E
pop
()
{
return
removeFirst
();
}
/**
* Removes the first element {@code e} such that
...
...
@@ -1385,6 +1404,99 @@ public class ConcurrentLinkedDeque<E>
Node
<
E
>
nextNode
(
Node
<
E
>
p
)
{
return
pred
(
p
);
}
}
/** A customized variant of Spliterators.IteratorSpliterator */
static
final
class
CLDSpliterator
<
E
>
implements
Spliterator
<
E
>
{
static
final
int
MAX_BATCH
=
1
<<
25
;
// max batch array size;
final
ConcurrentLinkedDeque
<
E
>
queue
;
Node
<
E
>
current
;
// current node; null until initialized
int
batch
;
// batch size for splits
boolean
exhausted
;
// true when no more nodes
CLDSpliterator
(
ConcurrentLinkedDeque
<
E
>
queue
)
{
this
.
queue
=
queue
;
}
public
Spliterator
<
E
>
trySplit
()
{
Node
<
E
>
p
;
final
ConcurrentLinkedDeque
<
E
>
q
=
this
.
queue
;
int
b
=
batch
;
int
n
=
(
b
<=
0
)
?
1
:
(
b
>=
MAX_BATCH
)
?
MAX_BATCH
:
b
+
1
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
))
{
if
(
p
.
item
==
null
&&
p
==
(
p
=
p
.
next
))
current
=
p
=
q
.
first
();
if
(
p
!=
null
&&
p
.
next
!=
null
)
{
Object
[]
a
=
new
Object
[
n
];
int
i
=
0
;
do
{
if
((
a
[
i
]
=
p
.
item
)
!=
null
)
++
i
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
}
while
(
p
!=
null
&&
i
<
n
);
if
((
current
=
p
)
==
null
)
exhausted
=
true
;
if
(
i
>
0
)
{
batch
=
i
;
return
Spliterators
.
spliterator
(
a
,
0
,
i
,
Spliterator
.
ORDERED
|
Spliterator
.
NONNULL
|
Spliterator
.
CONCURRENT
);
}
}
}
return
null
;
}
public
void
forEachRemaining
(
Consumer
<?
super
E
>
action
)
{
Node
<
E
>
p
;
if
(
action
==
null
)
throw
new
NullPointerException
();
final
ConcurrentLinkedDeque
<
E
>
q
=
this
.
queue
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
))
{
exhausted
=
true
;
do
{
E
e
=
p
.
item
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
if
(
e
!=
null
)
action
.
accept
(
e
);
}
while
(
p
!=
null
);
}
}
public
boolean
tryAdvance
(
Consumer
<?
super
E
>
action
)
{
Node
<
E
>
p
;
if
(
action
==
null
)
throw
new
NullPointerException
();
final
ConcurrentLinkedDeque
<
E
>
q
=
this
.
queue
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
))
{
E
e
;
do
{
e
=
p
.
item
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
}
while
(
e
==
null
&&
p
!=
null
);
if
((
current
=
p
)
==
null
)
exhausted
=
true
;
if
(
e
!=
null
)
{
action
.
accept
(
e
);
return
true
;
}
}
return
false
;
}
public
long
estimateSize
()
{
return
Long
.
MAX_VALUE
;
}
public
int
characteristics
()
{
return
Spliterator
.
ORDERED
|
Spliterator
.
NONNULL
|
Spliterator
.
CONCURRENT
;
}
}
public
Spliterator
<
E
>
spliterator
()
{
return
new
CLDSpliterator
<
E
>(
this
);
}
/**
* Saves this deque to a stream (that is, serializes it).
*
...
...
src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java
浏览文件 @
7bf1893e
...
...
@@ -41,6 +41,9 @@ import java.util.Collection;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
import
java.util.Queue
;
import
java.util.Spliterator
;
import
java.util.Spliterators
;
import
java.util.function.Consumer
;
/**
* An unbounded thread-safe {@linkplain Queue queue} based on linked nodes.
...
...
@@ -56,7 +59,7 @@ import java.util.Queue;
* Like most other concurrent collection implementations, this class
* does not permit the use of {@code null} elements.
*
* <p>This implementation employs an efficient
"wait-free"
* <p>This implementation employs an efficient
<em>non-blocking</em>
* algorithm based on one described in <a
* href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple,
* Fast, and Practical Non-Blocking and Blocking Concurrent Queue
...
...
@@ -295,7 +298,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
}
/**
* Tr
y
to CAS head to p. If successful, repoint old head to itself
* Tr
ies
to CAS head to p. If successful, repoint old head to itself
* as sentinel for succ(), below.
*/
final
void
updateHead
(
Node
<
E
>
h
,
Node
<
E
>
p
)
{
...
...
@@ -792,6 +795,96 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
tail
=
t
;
}
/** A customized variant of Spliterators.IteratorSpliterator */
static
final
class
CLQSpliterator
<
E
>
implements
Spliterator
<
E
>
{
static
final
int
MAX_BATCH
=
1
<<
25
;
// max batch array size;
final
ConcurrentLinkedQueue
<
E
>
queue
;
Node
<
E
>
current
;
// current node; null until initialized
int
batch
;
// batch size for splits
boolean
exhausted
;
// true when no more nodes
CLQSpliterator
(
ConcurrentLinkedQueue
<
E
>
queue
)
{
this
.
queue
=
queue
;
}
public
Spliterator
<
E
>
trySplit
()
{
Node
<
E
>
p
;
final
ConcurrentLinkedQueue
<
E
>
q
=
this
.
queue
;
int
b
=
batch
;
int
n
=
(
b
<=
0
)
?
1
:
(
b
>=
MAX_BATCH
)
?
MAX_BATCH
:
b
+
1
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
)
&&
p
.
next
!=
null
)
{
Object
[]
a
=
new
Object
[
n
];
int
i
=
0
;
do
{
if
((
a
[
i
]
=
p
.
item
)
!=
null
)
++
i
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
}
while
(
p
!=
null
&&
i
<
n
);
if
((
current
=
p
)
==
null
)
exhausted
=
true
;
if
(
i
>
0
)
{
batch
=
i
;
return
Spliterators
.
spliterator
(
a
,
0
,
i
,
Spliterator
.
ORDERED
|
Spliterator
.
NONNULL
|
Spliterator
.
CONCURRENT
);
}
}
return
null
;
}
public
void
forEachRemaining
(
Consumer
<?
super
E
>
action
)
{
Node
<
E
>
p
;
if
(
action
==
null
)
throw
new
NullPointerException
();
final
ConcurrentLinkedQueue
<
E
>
q
=
this
.
queue
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
))
{
exhausted
=
true
;
do
{
E
e
=
p
.
item
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
if
(
e
!=
null
)
action
.
accept
(
e
);
}
while
(
p
!=
null
);
}
}
public
boolean
tryAdvance
(
Consumer
<?
super
E
>
action
)
{
Node
<
E
>
p
;
if
(
action
==
null
)
throw
new
NullPointerException
();
final
ConcurrentLinkedQueue
<
E
>
q
=
this
.
queue
;
if
(!
exhausted
&&
((
p
=
current
)
!=
null
||
(
p
=
q
.
first
())
!=
null
))
{
E
e
;
do
{
e
=
p
.
item
;
if
(
p
==
(
p
=
p
.
next
))
p
=
q
.
first
();
}
while
(
e
==
null
&&
p
!=
null
);
if
((
current
=
p
)
==
null
)
exhausted
=
true
;
if
(
e
!=
null
)
{
action
.
accept
(
e
);
return
true
;
}
}
return
false
;
}
public
long
estimateSize
()
{
return
Long
.
MAX_VALUE
;
}
public
int
characteristics
()
{
return
Spliterator
.
ORDERED
|
Spliterator
.
NONNULL
|
Spliterator
.
CONCURRENT
;
}
}
public
Spliterator
<
E
>
spliterator
()
{
return
new
CLQSpliterator
<
E
>(
this
);
}
/**
* Throws NullPointerException if argument is null.
*
...
...
src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java
浏览文件 @
7bf1893e
...
...
@@ -34,7 +34,17 @@
*/
package
java.util.concurrent
;
import
java.util.*
;
import
java.util.AbstractSet
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.NavigableMap
;
import
java.util.NavigableSet
;
import
java.util.Set
;
import
java.util.SortedSet
;
import
java.util.Spliterator
;
/**
* A scalable concurrent {@link NavigableSet} implementation based on
...
...
@@ -44,33 +54,33 @@ import java.util.*;
* on which constructor is used.
*
* <p>This implementation provides expected average <i>log(n)</i> time
* cost for the
<tt>contains</tt>, <tt>add</tt>, and <tt>remove</tt>
* cost for the
{@code contains}, {@code add}, and {@code remove}
* operations and their variants. Insertion, removal, and access
* operations safely execute concurrently by multiple threads.
* Iterators are <i>weakly consistent</i>, returning elements
* reflecting the state of the set at some point at or since the
* creation of the iterator. They do <em>not</em> throw {@link
*
ConcurrentModificationException}, and may proceed concurrently with
*
other operations. Ascending ordered views and their iterators are
* faster than descending ones.
*
java.util.ConcurrentModificationException}, and may proceed
*
concurrently with other operations. Ascending ordered views and
*
their iterators are
faster than descending ones.
*
* <p>Beware that, unlike in most collections, the
<tt>size</tt>
* <p>Beware that, unlike in most collections, the
{@code size}
* method is <em>not</em> a constant-time operation. Because of the
* asynchronous nature of these sets, determining the current number
* of elements requires a traversal of the elements, and so may report
* inaccurate results if this collection is modified during traversal.
* Additionally, the bulk operations
<tt>addAll</tt>
,
*
<tt>removeAll</tt>, <tt>retainAll</tt>, <tt>containsAll</tt>
,
*
<tt>equals</tt>, and <tt>toArray</tt>
are <em>not</em> guaranteed
* Additionally, the bulk operations
{@code addAll}
,
*
{@code removeAll}, {@code retainAll}, {@code containsAll}
,
*
{@code equals}, and {@code toArray}
are <em>not</em> guaranteed
* to be performed atomically. For example, an iterator operating
* concurrently with an
<tt>addAll</tt>
operation might view only some
* concurrently with an
{@code addAll}
operation might view only some
* of the added elements.
*
* <p>This class and its iterators implement all of the
* <em>optional</em> methods of the {@link Set} and {@link Iterator}
* interfaces. Like most other concurrent collection implementations,
* this class does not permit the use of
<tt>null</tt>
elements,
* because
<tt>null</tt>
arguments and return values cannot be reliably
* this class does not permit the use of
{@code null}
elements,
* because
{@code null}
arguments and return values cannot be reliably
* distinguished from the absence of elements.
*
* <p>This class is a member of the
...
...
@@ -90,7 +100,7 @@ public class ConcurrentSkipListSet<E>
/**
* The underlying map. Uses Boolean.TRUE as value for each
* element. This field is declared final for the sake of thread
* safety, which entails some ugliness in clone()
* safety, which entails some ugliness in clone()
.
*/
private
final
ConcurrentNavigableMap
<
E
,
Object
>
m
;
...
...
@@ -107,7 +117,7 @@ public class ConcurrentSkipListSet<E>
* the specified comparator.
*
* @param comparator the comparator that will be used to order this set.
* If
<tt>null</tt>
, the {@linkplain Comparable natural
* If
{@code null}
, the {@linkplain Comparable natural
* ordering} of the elements will be used.
*/
public
ConcurrentSkipListSet
(
Comparator
<?
super
E
>
comparator
)
{
...
...
@@ -120,7 +130,7 @@ public class ConcurrentSkipListSet<E>
* {@linkplain Comparable natural ordering}.
*
* @param c The elements that will comprise the new set
* @throws ClassCastException if the elements in
<tt>c</tt>
are
* @throws ClassCastException if the elements in
{@code c}
are
* not {@link Comparable}, or are not mutually comparable
* @throws NullPointerException if the specified collection or any
* of its elements are null
...
...
@@ -151,7 +161,7 @@ public class ConcurrentSkipListSet<E>
}
/**
* Returns a shallow copy of this
<tt>ConcurrentSkipListSet</tt>
* Returns a shallow copy of this
{@code ConcurrentSkipListSet}
* instance. (The elements themselves are not cloned.)
*
* @return a shallow copy of this set
...
...
@@ -172,8 +182,8 @@ public class ConcurrentSkipListSet<E>
/**
* Returns the number of elements in this set. If this set
* contains more than
<tt>Integer.MAX_VALUE</tt>
elements, it
* returns
<tt>Integer.MAX_VALUE</tt>
.
* contains more than
{@code Integer.MAX_VALUE}
elements, it
* returns
{@code Integer.MAX_VALUE}
.
*
* <p>Beware that, unlike in most collections, this method is
* <em>NOT</em> a constant-time operation. Because of the
...
...
@@ -191,20 +201,20 @@ public class ConcurrentSkipListSet<E>
}
/**
* Returns
<tt>true</tt>
if this set contains no elements.
* @return
<tt>true</tt>
if this set contains no elements
* Returns
{@code true}
if this set contains no elements.
* @return
{@code true}
if this set contains no elements
*/
public
boolean
isEmpty
()
{
return
m
.
isEmpty
();
}
/**
* Returns
<tt>true</tt>
if this set contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this set
* contains an element
<tt>e</tt> such that <tt>o.equals(e)</tt>
.
* Returns
{@code true}
if this set contains the specified element.
* More formally, returns
{@code true}
if and only if this set
* contains an element
{@code e} such that {@code o.equals(e)}
.
*
* @param o object to be checked for containment in this set
* @return
<tt>true</tt>
if this set contains the specified element
* @return
{@code true}
if this set contains the specified element
* @throws ClassCastException if the specified element cannot be
* compared with the elements currently in this set
* @throws NullPointerException if the specified element is null
...
...
@@ -215,15 +225,15 @@ public class ConcurrentSkipListSet<E>
/**
* Adds the specified element to this set if it is not already present.
* More formally, adds the specified element
<tt>e</tt>
to this set if
* the set contains no element
<tt>e2</tt> such that <tt>e.equals(e2)</tt>
.
* More formally, adds the specified element
{@code e}
to this set if
* the set contains no element
{@code e2} such that {@code e.equals(e2)}
.
* If this set already contains the element, the call leaves the set
* unchanged and returns
<tt>false</tt>
.
* unchanged and returns
{@code false}
.
*
* @param e element to be added to this set
* @return
<tt>true</tt>
if this set did not already contain the
* @return
{@code true}
if this set did not already contain the
* specified element
* @throws ClassCastException if
<tt>e</tt>
cannot be compared
* @throws ClassCastException if
{@code e}
cannot be compared
* with the elements currently in this set
* @throws NullPointerException if the specified element is null
*/
...
...
@@ -233,15 +243,15 @@ public class ConcurrentSkipListSet<E>
/**
* Removes the specified element from this set if it is present.
* More formally, removes an element
<tt>e</tt>
such that
*
<tt>o.equals(e)</tt>
, if this set contains such an element.
* Returns
<tt>true</tt>
if this set contained the element (or
* More formally, removes an element
{@code e}
such that
*
{@code o.equals(e)}
, if this set contains such an element.
* Returns
{@code true}
if this set contained the element (or
* equivalently, if this set changed as a result of the call).
* (This set will not contain the element once the call returns.)
*
* @param o object to be removed from this set, if present
* @return
<tt>true</tt>
if this set contained the specified element
* @throws ClassCastException if
<tt>o</tt>
cannot be compared
* @return
{@code true}
if this set contained the specified element
* @throws ClassCastException if
{@code o}
cannot be compared
* with the elements currently in this set
* @throws NullPointerException if the specified element is null
*/
...
...
@@ -279,7 +289,7 @@ public class ConcurrentSkipListSet<E>
/**
* Compares the specified object with this set for equality. Returns
*
<tt>true</tt>
if the specified object is also a set, the two sets
*
{@code true}
if the specified object is also a set, the two sets
* have the same size, and every member of the specified set is
* contained in this set (or equivalently, every member of this set is
* contained in the specified set). This definition ensures that the
...
...
@@ -287,7 +297,7 @@ public class ConcurrentSkipListSet<E>
* set interface.
*
* @param o the object to be compared for equality with this set
* @return
<tt>true</tt>
if the specified object is equal to this set
* @return
{@code true}
if the specified object is equal to this set
*/
public
boolean
equals
(
Object
o
)
{
// Override AbstractSet version to avoid calling size()
...
...
@@ -312,7 +322,7 @@ public class ConcurrentSkipListSet<E>
* value is the <i>asymmetric set difference</i> of the two sets.
*
* @param c collection containing elements to be removed from this set
* @return
<tt>true</tt>
if this set changed as a result of the call
* @return
{@code true}
if this set changed as a result of the call
* @throws ClassCastException if the types of one or more elements in this
* set are incompatible with the specified collection
* @throws NullPointerException if the specified collection or any
...
...
@@ -380,14 +390,14 @@ public class ConcurrentSkipListSet<E>
}
/**
* @throws NoSuchElementException {@inheritDoc}
* @throws
java.util.
NoSuchElementException {@inheritDoc}
*/
public
E
first
()
{
return
m
.
firstKey
();
}
/**
* @throws NoSuchElementException {@inheritDoc}
* @throws
java.util.
NoSuchElementException {@inheritDoc}
*/
public
E
last
()
{
return
m
.
lastKey
();
...
...
@@ -460,7 +470,7 @@ public class ConcurrentSkipListSet<E>
* reflected in the descending set, and vice-versa.
*
* <p>The returned set has an ordering equivalent to
*
<tt>{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator())</tt>
.
*
{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}
.
* The expression {@code s.descendingSet().descendingSet()} returns a
* view of {@code s} essentially equivalent to {@code s}.
*
...
...
@@ -470,6 +480,14 @@ public class ConcurrentSkipListSet<E>
return
new
ConcurrentSkipListSet
<
E
>(
m
.
descendingMap
());
}
@SuppressWarnings
(
"unchecked"
)
public
Spliterator
<
E
>
spliterator
()
{
if
(
m
instanceof
ConcurrentSkipListMap
)
return
((
ConcurrentSkipListMap
<
E
,?>)
m
).
keySpliterator
();
else
return
(
Spliterator
<
E
>)((
ConcurrentSkipListMap
.
SubMap
<
E
,?>)
m
).
keyIterator
();
}
// Support for resetting map in clone
private
void
setMap
(
ConcurrentNavigableMap
<
E
,
Object
>
map
)
{
UNSAFE
.
putObjectVolatile
(
this
,
mapOffset
,
map
);
...
...
src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
浏览文件 @
7bf1893e
...
...
@@ -34,7 +34,14 @@
*/
package
java.util.concurrent
;
import
java.util.*
;
import
java.util.Collection
;
import
java.util.Set
;
import
java.util.AbstractSet
;
import
java.util.Iterator
;
import
java.util.Spliterator
;
import
java.util.Spliterators
;
import
java.util.function.Predicate
;
import
java.util.function.Consumer
;
/**
* A {@link java.util.Set} that uses an internal {@link CopyOnWriteArrayList}
...
...
@@ -45,17 +52,17 @@ import java.util.*;
* vastly outnumber mutative operations, and you need
* to prevent interference among threads during traversal.
* <li>It is thread-safe.
* <li>Mutative operations (
<tt>add</tt>, <tt>set</tt>, <tt>remove</tt>
, etc.)
* <li>Mutative operations (
{@code add}, {@code set}, {@code remove}
, etc.)
* are expensive since they usually entail copying the entire underlying
* array.
* <li>Iterators do not support the mutative
<tt>remove</tt>
operation.
* <li>Iterators do not support the mutative
{@code remove}
operation.
* <li>Traversal via iterators is fast and cannot encounter
* interference from other threads. Iterators rely on
* unchanging snapshots of the array at the time the iterators were
* constructed.
* </ul>
*
* <p>
<b>Sample Usage.</b> The following code sketch uses a
* <p><b>Sample Usage.</b> The following code sketch uses a
* copy-on-write set to maintain a set of Handler objects that
* perform some action upon state updates.
*
...
...
@@ -73,7 +80,7 @@ import java.util.*;
* public void update() {
* changeState();
* for (Handler handler : handlers)
*
handler.handle();
* handler.handle();
* }
* }}</pre>
*
...
...
@@ -107,8 +114,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* @throws NullPointerException if the specified collection is null
*/
public
CopyOnWriteArraySet
(
Collection
<?
extends
E
>
c
)
{
al
=
new
CopyOnWriteArrayList
<
E
>();
al
.
addAllAbsent
(
c
);
if
(
c
.
getClass
()
==
CopyOnWriteArraySet
.
class
)
{
@SuppressWarnings
(
"unchecked"
)
CopyOnWriteArraySet
<
E
>
cc
=
(
CopyOnWriteArraySet
<
E
>)
c
;
al
=
new
CopyOnWriteArrayList
<
E
>(
cc
.
al
);
}
else
{
al
=
new
CopyOnWriteArrayList
<
E
>();
al
.
addAllAbsent
(
c
);
}
}
/**
...
...
@@ -121,22 +135,22 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
}
/**
* Returns
<tt>true</tt>
if this set contains no elements.
* Returns
{@code true}
if this set contains no elements.
*
* @return
<tt>true</tt>
if this set contains no elements
* @return
{@code true}
if this set contains no elements
*/
public
boolean
isEmpty
()
{
return
al
.
isEmpty
();
}
/**
* Returns
<tt>true</tt>
if this set contains the specified element.
* More formally, returns
<tt>true</tt>
if and only if this set
* contains an element
<tt>e</tt>
such that
* Returns
{@code true}
if this set contains the specified element.
* More formally, returns
{@code true}
if and only if this set
* contains an element
{@code e}
such that
* <tt>(o==null ? e==null : o.equals(e))</tt>.
*
* @param o element whose presence in this set is to be tested
* @return
<tt>true</tt>
if this set contains the specified element
* @return
{@code true}
if this set contains the specified element
*/
public
boolean
contains
(
Object
o
)
{
return
al
.
contains
(
o
);
...
...
@@ -172,7 +186,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>If this set fits in the specified array with room to spare
* (i.e., the array has more elements than this set), the element in
* the array immediately following the end of the set is set to
*
<tt>null</tt>
. (This is useful in determining the length of this
*
{@code null}
. (This is useful in determining the length of this
* set <i>only</i> if the caller knows that this set does not contain
* any null elements.)
*
...
...
@@ -185,14 +199,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs.
*
* <p>Suppose
<tt>x</tt>
is a set known to contain only strings.
* <p>Suppose
{@code x}
is a set known to contain only strings.
* The following code can be used to dump the set into a newly allocated
* array of
<tt>String</tt>
:
* array of
{@code String}
:
*
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre>
*
* Note that
<tt>toArray(new Object[0])</tt>
is identical in function to
*
<tt>toArray()</tt>
.
* Note that
{@code toArray(new Object[0])}
is identical in function to
*
{@code toArray()}
.
*
* @param a the array into which the elements of this set are to be
* stored, if it is big enough; otherwise, a new array of the same
...
...
@@ -217,15 +231,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* Removes the specified element from this set if it is present.
* More formally, removes an element
<tt>e</tt>
such that
* More formally, removes an element
{@code e}
such that
* <tt>(o==null ? e==null : o.equals(e))</tt>,
* if this set contains such an element. Returns
<tt>true</tt>
if
* if this set contains such an element. Returns
{@code true}
if
* this set contained the element (or equivalently, if this set
* changed as a result of the call). (This set will not contain the
* element once the call returns.)
*
* @param o object to be removed from this set, if present
* @return
<tt>true</tt>
if this set contained the specified element
* @return
{@code true}
if this set contained the specified element
*/
public
boolean
remove
(
Object
o
)
{
return
al
.
remove
(
o
);
...
...
@@ -233,14 +247,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* Adds the specified element to this set if it is not already present.
* More formally, adds the specified element
<tt>e</tt>
to this set if
* the set contains no element
<tt>e2</tt>
such that
* More formally, adds the specified element
{@code e}
to this set if
* the set contains no element
{@code e2}
such that
* <tt>(e==null ? e2==null : e.equals(e2))</tt>.
* If this set already contains the element, the call leaves the set
* unchanged and returns
<tt>false</tt>
.
* unchanged and returns
{@code false}
.
*
* @param e element to be added to this set
* @return
<tt>true</tt>
if this set did not already contain the specified
* @return
{@code true}
if this set did not already contain the specified
* element
*/
public
boolean
add
(
E
e
)
{
...
...
@@ -248,12 +262,12 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
}
/**
* Returns
<tt>true</tt>
if this set contains all of the elements of the
* Returns
{@code true}
if this set contains all of the elements of the
* specified collection. If the specified collection is also a set, this
* method returns
<tt>true</tt>
if it is a <i>subset</i> of this set.
* method returns
{@code true}
if it is a <i>subset</i> of this set.
*
* @param c collection to be checked for containment in this set
* @return
<tt>true</tt>
if this set contains all of the elements of the
* @return
{@code true}
if this set contains all of the elements of the
* specified collection
* @throws NullPointerException if the specified collection is null
* @see #contains(Object)
...
...
@@ -265,13 +279,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/**
* Adds all of the elements in the specified collection to this set if
* they're not already present. If the specified collection is also a
* set, the
<tt>addAll</tt>
operation effectively modifies this set so
* set, the
{@code addAll}
operation effectively modifies this set so
* that its value is the <i>union</i> of the two sets. The behavior of
* this operation is undefined if the specified collection is modified
* while the operation is in progress.
*
* @param c collection containing elements to be added to this set
* @return
<tt>true</tt>
if this set changed as a result of the call
* @return
{@code true}
if this set changed as a result of the call
* @throws NullPointerException if the specified collection is null
* @see #add(Object)
*/
...
...
@@ -286,7 +300,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <i>asymmetric set difference</i> of the two sets.
*
* @param c collection containing elements to be removed from this set
* @return
<tt>true</tt>
if this set changed as a result of the call
* @return
{@code true}
if this set changed as a result of the call
* @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the
...
...
@@ -307,7 +321,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* two sets.
*
* @param c collection containing elements to be retained in this set
* @return
<tt>true</tt>
if this set changed as a result of the call
* @return
{@code true}
if this set changed as a result of the call
* @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the
...
...
@@ -326,7 +340,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>The returned iterator provides a snapshot of the state of the set
* when the iterator was constructed. No synchronization is needed while
* traversing the iterator. The iterator does <em>NOT</em> support the
*
<tt>remove</tt>
method.
*
{@code remove}
method.
*
* @return an iterator over the elements in this set
*/
...
...
@@ -338,7 +352,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* Compares the specified object with this set for equality.
* Returns {@code true} if the specified object is the same object
* as this object, or if it is also a {@link Set} and the elements
* returned by an {@linkplain
Lis
t#iterator() iterator} over the
* returned by an {@linkplain
Se
t#iterator() iterator} over the
* specified set are the same as the elements returned by an
* iterator over this set. More formally, the two iterators are
* considered to return the same elements if they return the same
...
...
@@ -382,6 +396,19 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
return
k
==
len
;
}
public
boolean
removeIf
(
Predicate
<?
super
E
>
filter
)
{
return
al
.
removeIf
(
filter
);
}
public
void
forEach
(
Consumer
<?
super
E
>
action
)
{
al
.
forEach
(
action
);
}
public
Spliterator
<
E
>
spliterator
()
{
return
Spliterators
.
spliterator
(
al
.
getArray
(),
Spliterator
.
IMMUTABLE
|
Spliterator
.
DISTINCT
);
}
/**
* Tests for equality, coping with nulls.
*/
...
...
src/share/classes/java/util/concurrent/DelayQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/Delayed.java
浏览文件 @
7bf1893e
...
...
@@ -40,8 +40,8 @@ package java.util.concurrent;
* acted upon after a given delay.
*
* <p>An implementation of this interface must define a
*
<tt>compareTo</tt>
method that provides an ordering consistent with
* its
<tt>getDelay</tt>
method.
*
{@code compareTo}
method that provides an ordering consistent with
* its
{@code getDelay}
method.
*
* @since 1.5
* @author Doug Lea
...
...
src/share/classes/java/util/concurrent/LinkedBlockingDeque.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/LinkedBlockingQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/LinkedTransferQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
src/share/classes/java/util/concurrent/SynchronousQueue.java
浏览文件 @
7bf1893e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录