ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jdk7/java/util/concurrent/BlockingQueue.java
(Generate patch)

Comparing jsr166/src/jdk7/java/util/concurrent/BlockingQueue.java (file contents):
Revision 1.1 by dl, Sun Dec 16 20:55:15 2012 UTC vs.
Revision 1.2 by jsr166, Wed Jan 16 01:39:37 2013 UTC

# Line 15 | Line 15 | import java.util.Queue;
15   * element, and wait for space to become available in the queue when
16   * storing an element.
17   *
18 < * <p><tt>BlockingQueue</tt> methods come in four forms, with different ways
18 > * <p>{@code BlockingQueue} methods come in four forms, with different ways
19   * of handling operations that cannot be satisfied immediately, but may be
20   * satisfied at some point in the future:
21   * one throws an exception, the second returns a special value (either
22 < * <tt>null</tt> or <tt>false</tt>, depending on the operation), the third
22 > * {@code null} or {@code false}, depending on the operation), the third
23   * blocks the current thread indefinitely until the operation can succeed,
24   * and the fourth blocks for only a given maximum time limit before giving
25   * up.  These methods are summarized in the following table:
# Line 56 | Line 56 | import java.util.Queue;
56   *  </tr>
57   * </table>
58   *
59 < * <p>A <tt>BlockingQueue</tt> does not accept <tt>null</tt> elements.
60 < * Implementations throw <tt>NullPointerException</tt> on attempts
61 < * to <tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>.  A
62 < * <tt>null</tt> is used as a sentinel value to indicate failure of
63 < * <tt>poll</tt> operations.
64 < *
65 < * <p>A <tt>BlockingQueue</tt> may be capacity bounded. At any given
66 < * time it may have a <tt>remainingCapacity</tt> beyond which no
67 < * additional elements can be <tt>put</tt> without blocking.
68 < * A <tt>BlockingQueue</tt> without any intrinsic capacity constraints always
69 < * reports a remaining capacity of <tt>Integer.MAX_VALUE</tt>.
59 > * <p>A {@code BlockingQueue} does not accept {@code null} elements.
60 > * Implementations throw {@code NullPointerException} on attempts
61 > * to {@code add}, {@code put} or {@code offer} a {@code null}.  A
62 > * {@code null} is used as a sentinel value to indicate failure of
63 > * {@code poll} operations.
64 > *
65 > * <p>A {@code BlockingQueue} may be capacity bounded. At any given
66 > * time it may have a {@code remainingCapacity} beyond which no
67 > * additional elements can be {@code put} without blocking.
68 > * A {@code BlockingQueue} without any intrinsic capacity constraints always
69 > * reports a remaining capacity of {@code Integer.MAX_VALUE}.
70   *
71 < * <p><tt>BlockingQueue</tt> implementations are designed to be used
71 > * <p>{@code BlockingQueue} implementations are designed to be used
72   * primarily for producer-consumer queues, but additionally support
73   * the {@link java.util.Collection} interface.  So, for example, it is
74   * possible to remove an arbitrary element from a queue using
75 < * <tt>remove(x)</tt>. However, such operations are in general
75 > * {@code remove(x)}. However, such operations are in general
76   * <em>not</em> performed very efficiently, and are intended for only
77   * occasional use, such as when a queued message is cancelled.
78   *
79 < * <p><tt>BlockingQueue</tt> implementations are thread-safe.  All
79 > * <p>{@code BlockingQueue} implementations are thread-safe.  All
80   * queuing methods achieve their effects atomically using internal
81   * locks or other forms of concurrency control. However, the
82 < * <em>bulk</em> Collection operations <tt>addAll</tt>,
83 < * <tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt> are
82 > * <em>bulk</em> Collection operations {@code addAll},
83 > * {@code containsAll}, {@code retainAll} and {@code removeAll} are
84   * <em>not</em> necessarily performed atomically unless specified
85   * otherwise in an implementation. So it is possible, for example, for
86 < * <tt>addAll(c)</tt> to fail (throwing an exception) after adding
87 < * only some of the elements in <tt>c</tt>.
86 > * {@code addAll(c)} to fail (throwing an exception) after adding
87 > * only some of the elements in {@code c}.
88   *
89 < * <p>A <tt>BlockingQueue</tt> does <em>not</em> intrinsically support
89 > * <p>A {@code BlockingQueue} does <em>not</em> intrinsically support
90   * any kind of &quot;close&quot; or &quot;shutdown&quot; operation to
91   * indicate that no more items will be added.  The needs and usage of
92   * such features tend to be implementation-dependent. For example, a
# Line 96 | Line 96 | import java.util.Queue;
96   *
97   * <p>
98   * Usage example, based on a typical producer-consumer scenario.
99 < * Note that a <tt>BlockingQueue</tt> can safely be used with multiple
99 > * Note that a {@code BlockingQueue} can safely be used with multiple
100   * producers and multiple consumers.
101   *  <pre> {@code
102   * class Producer implements Runnable {
# Line 152 | Line 152 | public interface BlockingQueue<E> extend
152      /**
153       * Inserts the specified element into this queue if it is possible to do
154       * so immediately without violating capacity restrictions, returning
155 <     * <tt>true</tt> upon success and throwing an
156 <     * <tt>IllegalStateException</tt> if no space is currently available.
155 >     * {@code true} upon success and throwing an
156 >     * {@code IllegalStateException} if no space is currently available.
157       * When using a capacity-restricted queue, it is generally preferable to
158       * use {@link #offer(Object) offer}.
159       *
160       * @param e the element to add
161 <     * @return <tt>true</tt> (as specified by {@link Collection#add})
161 >     * @return {@code true} (as specified by {@link Collection#add})
162       * @throws IllegalStateException if the element cannot be added at this
163       *         time due to capacity restrictions
164       * @throws ClassCastException if the class of the specified element
# Line 172 | Line 172 | public interface BlockingQueue<E> extend
172      /**
173       * Inserts the specified element into this queue if it is possible to do
174       * so immediately without violating capacity restrictions, returning
175 <     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
175 >     * {@code true} upon success and {@code false} if no space is currently
176       * available.  When using a capacity-restricted queue, this method is
177       * generally preferable to {@link #add}, which can fail to insert an
178       * element only by throwing an exception.
179       *
180       * @param e the element to add
181 <     * @return <tt>true</tt> if the element was added to this queue, else
182 <     *         <tt>false</tt>
181 >     * @return {@code true} if the element was added to this queue, else
182 >     *         {@code false}
183       * @throws ClassCastException if the class of the specified element
184       *         prevents it from being added to this queue
185       * @throws NullPointerException if the specified element is null
# Line 208 | Line 208 | public interface BlockingQueue<E> extend
208       *
209       * @param e the element to add
210       * @param timeout how long to wait before giving up, in units of
211 <     *        <tt>unit</tt>
212 <     * @param unit a <tt>TimeUnit</tt> determining how to interpret the
213 <     *        <tt>timeout</tt> parameter
214 <     * @return <tt>true</tt> if successful, or <tt>false</tt> if
211 >     *        {@code unit}
212 >     * @param unit a {@code TimeUnit} determining how to interpret the
213 >     *        {@code timeout} parameter
214 >     * @return {@code true} if successful, or {@code false} if
215       *         the specified waiting time elapses before space is available
216       * @throws InterruptedException if interrupted while waiting
217       * @throws ClassCastException if the class of the specified element
# Line 237 | Line 237 | public interface BlockingQueue<E> extend
237       * specified wait time if necessary for an element to become available.
238       *
239       * @param timeout how long to wait before giving up, in units of
240 <     *        <tt>unit</tt>
241 <     * @param unit a <tt>TimeUnit</tt> determining how to interpret the
242 <     *        <tt>timeout</tt> parameter
243 <     * @return the head of this queue, or <tt>null</tt> if the
240 >     *        {@code unit}
241 >     * @param unit a {@code TimeUnit} determining how to interpret the
242 >     *        {@code timeout} parameter
243 >     * @return the head of this queue, or {@code null} if the
244       *         specified waiting time elapses before an element is available
245       * @throws InterruptedException if interrupted while waiting
246       */
# Line 250 | Line 250 | public interface BlockingQueue<E> extend
250      /**
251       * Returns the number of additional elements that this queue can ideally
252       * (in the absence of memory or resource constraints) accept without
253 <     * blocking, or <tt>Integer.MAX_VALUE</tt> if there is no intrinsic
253 >     * blocking, or {@code Integer.MAX_VALUE} if there is no intrinsic
254       * limit.
255       *
256       * <p>Note that you <em>cannot</em> always tell if an attempt to insert
257 <     * an element will succeed by inspecting <tt>remainingCapacity</tt>
257 >     * an element will succeed by inspecting {@code remainingCapacity}
258       * because it may be the case that another thread is about to
259       * insert or remove an element.
260       *
# Line 264 | Line 264 | public interface BlockingQueue<E> extend
264  
265      /**
266       * Removes a single instance of the specified element from this queue,
267 <     * if it is present.  More formally, removes an element <tt>e</tt> such
268 <     * that <tt>o.equals(e)</tt>, if this queue contains one or more such
267 >     * if it is present.  More formally, removes an element {@code e} such
268 >     * that {@code o.equals(e)}, if this queue contains one or more such
269       * elements.
270 <     * Returns <tt>true</tt> if this queue contained the specified element
270 >     * Returns {@code true} if this queue contained the specified element
271       * (or equivalently, if this queue changed as a result of the call).
272       *
273       * @param o element to be removed from this queue, if present
274 <     * @return <tt>true</tt> if this queue changed as a result of the call
274 >     * @return {@code true} if this queue changed as a result of the call
275       * @throws ClassCastException if the class of the specified element
276       *         is incompatible with this queue
277       *         (<a href="../Collection.html#optional-restrictions">optional</a>)
# Line 281 | Line 281 | public interface BlockingQueue<E> extend
281      boolean remove(Object o);
282  
283      /**
284 <     * Returns <tt>true</tt> if this queue contains the specified element.
285 <     * More formally, returns <tt>true</tt> if and only if this queue contains
286 <     * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
284 >     * Returns {@code true} if this queue contains the specified element.
285 >     * More formally, returns {@code true} if and only if this queue contains
286 >     * at least one element {@code e} such that {@code o.equals(e)}.
287       *
288       * @param o object to be checked for containment in this queue
289 <     * @return <tt>true</tt> if this queue contains the specified element
289 >     * @return {@code true} if this queue contains the specified element
290       * @throws ClassCastException if the class of the specified element
291       *         is incompatible with this queue
292       *         (<a href="../Collection.html#optional-restrictions">optional</a>)
# Line 300 | Line 300 | public interface BlockingQueue<E> extend
300       * to the given collection.  This operation may be more
301       * efficient than repeatedly polling this queue.  A failure
302       * encountered while attempting to add elements to
303 <     * collection <tt>c</tt> may result in elements being in neither,
303 >     * collection {@code c} may result in elements being in neither,
304       * either or both collections when the associated exception is
305       * thrown.  Attempts to drain a queue to itself result in
306 <     * <tt>IllegalArgumentException</tt>. Further, the behavior of
306 >     * {@code IllegalArgumentException}. Further, the behavior of
307       * this operation is undefined if the specified collection is
308       * modified while the operation is in progress.
309       *
# Line 324 | Line 324 | public interface BlockingQueue<E> extend
324       * Removes at most the given number of available elements from
325       * this queue and adds them to the given collection.  A failure
326       * encountered while attempting to add elements to
327 <     * collection <tt>c</tt> may result in elements being in neither,
327 >     * collection {@code c} may result in elements being in neither,
328       * either or both collections when the associated exception is
329       * thrown.  Attempts to drain a queue to itself result in
330 <     * <tt>IllegalArgumentException</tt>. Further, the behavior of
330 >     * {@code IllegalArgumentException}. Further, the behavior of
331       * this operation is undefined if the specified collection is
332       * modified while the operation is in progress.
333       *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines