Commit 91770798 authored by Calin Juravle's avatar Calin Juravle
Browse files

Sync java.util.concurrent library up to 12.06.2013.

CouncurrentHashMap was skipped from this sync.

Change-Id: I29c67698a2e706b22e3cb5920c5fe91f1f15461c
parent 0897c605
...@@ -9,19 +9,19 @@ import java.util.*; ...@@ -9,19 +9,19 @@ import java.util.*;
/** /**
* Provides default implementations of {@link ExecutorService} * Provides default implementations of {@link ExecutorService}
* execution methods. This class implements the <tt>submit</tt>, * execution methods. This class implements the {@code submit},
* <tt>invokeAny</tt> and <tt>invokeAll</tt> methods using a * {@code invokeAny} and {@code invokeAll} methods using a
* {@link RunnableFuture} returned by <tt>newTaskFor</tt>, which defaults * {@link RunnableFuture} returned by {@code newTaskFor}, which defaults
* to the {@link FutureTask} class provided in this package. For example, * to the {@link FutureTask} class provided in this package. For example,
* the implementation of <tt>submit(Runnable)</tt> creates an * the implementation of {@code submit(Runnable)} creates an
* associated <tt>RunnableFuture</tt> that is executed and * associated {@code RunnableFuture} that is executed and
* returned. Subclasses may override the <tt>newTaskFor</tt> methods * returned. Subclasses may override the {@code newTaskFor} methods
* to return <tt>RunnableFuture</tt> implementations other than * to return {@code RunnableFuture} implementations other than
* <tt>FutureTask</tt>. * {@code FutureTask}.
* *
* <p> <b>Extension example</b>. Here is a sketch of a class * <p><b>Extension example</b>. Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use * that customizes {@link ThreadPoolExecutor} to use
* a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: * a {@code CustomTask} class instead of the default {@code FutureTask}:
* <pre> {@code * <pre> {@code
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor { * public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
* *
...@@ -42,15 +42,15 @@ import java.util.*; ...@@ -42,15 +42,15 @@ import java.util.*;
public abstract class AbstractExecutorService implements ExecutorService { public abstract class AbstractExecutorService implements ExecutorService {
/** /**
* Returns a <tt>RunnableFuture</tt> for the given runnable and default * Returns a {@code RunnableFuture} for the given runnable and default
* value. * value.
* *
* @param runnable the runnable task being wrapped * @param runnable the runnable task being wrapped
* @param value the default value for the returned future * @param value the default value for the returned future
* @return a <tt>RunnableFuture</tt> which when run will run the * @return a {@code RunnableFuture} which, when run, will run the
* underlying runnable and which, as a <tt>Future</tt>, will yield * underlying runnable and which, as a {@code Future}, will yield
* the given value as its result and provide for cancellation of * the given value as its result and provide for cancellation of
* the underlying task. * the underlying task
* @since 1.6 * @since 1.6
*/ */
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
...@@ -58,13 +58,13 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -58,13 +58,13 @@ public abstract class AbstractExecutorService implements ExecutorService {
} }
/** /**
* Returns a <tt>RunnableFuture</tt> for the given callable task. * Returns a {@code RunnableFuture} for the given callable task.
* *
* @param callable the callable task being wrapped * @param callable the callable task being wrapped
* @return a <tt>RunnableFuture</tt> which when run will call the * @return a {@code RunnableFuture} which, when run, will call the
* underlying callable and which, as a <tt>Future</tt>, will yield * underlying callable and which, as a {@code Future}, will yield
* the callable's result as its result and provide for * the callable's result as its result and provide for
* cancellation of the underlying task. * cancellation of the underlying task
* @since 1.6 * @since 1.6
*/ */
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
...@@ -108,14 +108,14 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -108,14 +108,14 @@ public abstract class AbstractExecutorService implements ExecutorService {
* the main mechanics of invokeAny. * the main mechanics of invokeAny.
*/ */
private <T> T doInvokeAny(Collection<? extends Callable<T>> tasks, private <T> T doInvokeAny(Collection<? extends Callable<T>> tasks,
boolean timed, long nanos) boolean timed, long nanos)
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
if (tasks == null) if (tasks == null)
throw new NullPointerException(); throw new NullPointerException();
int ntasks = tasks.size(); int ntasks = tasks.size();
if (ntasks == 0) if (ntasks == 0)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
List<Future<T>> futures= new ArrayList<Future<T>>(ntasks); ArrayList<Future<T>> futures = new ArrayList<Future<T>>(ntasks);
ExecutorCompletionService<T> ecs = ExecutorCompletionService<T> ecs =
new ExecutorCompletionService<T>(this); new ExecutorCompletionService<T>(this);
...@@ -129,7 +129,7 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -129,7 +129,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
// Record exceptions so that if we fail to obtain any // Record exceptions so that if we fail to obtain any
// result, we can throw the last exception we got. // result, we can throw the last exception we got.
ExecutionException ee = null; ExecutionException ee = null;
long lastTime = timed ? System.nanoTime() : 0; final long deadline = timed ? System.nanoTime() + nanos : 0L;
Iterator<? extends Callable<T>> it = tasks.iterator(); Iterator<? extends Callable<T>> it = tasks.iterator();
// Start one task for sure; the rest incrementally // Start one task for sure; the rest incrementally
...@@ -151,9 +151,7 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -151,9 +151,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
f = ecs.poll(nanos, TimeUnit.NANOSECONDS); f = ecs.poll(nanos, TimeUnit.NANOSECONDS);
if (f == null) if (f == null)
throw new TimeoutException(); throw new TimeoutException();
long now = System.nanoTime(); nanos = deadline - System.nanoTime();
nanos -= now - lastTime;
lastTime = now;
} }
else else
f = ecs.take(); f = ecs.take();
...@@ -175,8 +173,8 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -175,8 +173,8 @@ public abstract class AbstractExecutorService implements ExecutorService {
throw ee; throw ee;
} finally { } finally {
for (Future<T> f : futures) for (int i = 0, size = futures.size(); i < size; i++)
f.cancel(true); futures.get(i).cancel(true);
} }
} }
...@@ -200,7 +198,7 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -200,7 +198,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
throws InterruptedException { throws InterruptedException {
if (tasks == null) if (tasks == null)
throw new NullPointerException(); throw new NullPointerException();
List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size()); ArrayList<Future<T>> futures = new ArrayList<Future<T>>(tasks.size());
boolean done = false; boolean done = false;
try { try {
for (Callable<T> t : tasks) { for (Callable<T> t : tasks) {
...@@ -208,7 +206,8 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -208,7 +206,8 @@ public abstract class AbstractExecutorService implements ExecutorService {
futures.add(f); futures.add(f);
execute(f); execute(f);
} }
for (Future<T> f : futures) { for (int i = 0, size = futures.size(); i < size; i++) {
Future<T> f = futures.get(i);
if (!f.isDone()) { if (!f.isDone()) {
try { try {
f.get(); f.get();
...@@ -221,40 +220,39 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -221,40 +220,39 @@ public abstract class AbstractExecutorService implements ExecutorService {
return futures; return futures;
} finally { } finally {
if (!done) if (!done)
for (Future<T> f : futures) for (int i = 0, size = futures.size(); i < size; i++)
f.cancel(true); futures.get(i).cancel(true);
} }
} }
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit) long timeout, TimeUnit unit)
throws InterruptedException { throws InterruptedException {
if (tasks == null || unit == null) if (tasks == null)
throw new NullPointerException(); throw new NullPointerException();
long nanos = unit.toNanos(timeout); long nanos = unit.toNanos(timeout);
List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size()); ArrayList<Future<T>> futures = new ArrayList<Future<T>>(tasks.size());
boolean done = false; boolean done = false;
try { try {
for (Callable<T> t : tasks) for (Callable<T> t : tasks)
futures.add(newTaskFor(t)); futures.add(newTaskFor(t));
long lastTime = System.nanoTime(); final long deadline = System.nanoTime() + nanos;
final int size = futures.size();
// Interleave time checks and calls to execute in case // Interleave time checks and calls to execute in case
// executor doesn't have any/much parallelism. // executor doesn't have any/much parallelism.
Iterator<Future<T>> it = futures.iterator(); for (int i = 0; i < size; i++) {
while (it.hasNext()) { execute((Runnable)futures.get(i));
execute((Runnable)(it.next())); nanos = deadline - System.nanoTime();
long now = System.nanoTime(); if (nanos <= 0L)
nanos -= now - lastTime;
lastTime = now;
if (nanos <= 0)
return futures; return futures;
} }
for (Future<T> f : futures) { for (int i = 0; i < size; i++) {
Future<T> f = futures.get(i);
if (!f.isDone()) { if (!f.isDone()) {
if (nanos <= 0) if (nanos <= 0L)
return futures; return futures;
try { try {
f.get(nanos, TimeUnit.NANOSECONDS); f.get(nanos, TimeUnit.NANOSECONDS);
...@@ -263,17 +261,15 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -263,17 +261,15 @@ public abstract class AbstractExecutorService implements ExecutorService {
} catch (TimeoutException toe) { } catch (TimeoutException toe) {
return futures; return futures;
} }
long now = System.nanoTime(); nanos = deadline - System.nanoTime();
nanos -= now - lastTime;
lastTime = now;
} }
} }
done = true; done = true;
return futures; return futures;
} finally { } finally {
if (!done) if (!done)
for (Future<T> f : futures) for (int i = 0, size = futures.size(); i < size; i++)
f.cancel(true); futures.get(i).cancel(true);
} }
} }
......
...@@ -111,9 +111,9 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -111,9 +111,9 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
/** /**
* Returns item at index i. * Returns item at index i.
*/ */
@SuppressWarnings("unchecked")
final E itemAt(int i) { final E itemAt(int i) {
@SuppressWarnings("unchecked") E x = (E) items[i]; return (E) items[i];
return x;
} }
/** /**
...@@ -147,7 +147,8 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -147,7 +147,8 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
// assert lock.getHoldCount() == 1; // assert lock.getHoldCount() == 1;
// assert items[takeIndex] != null; // assert items[takeIndex] != null;
final Object[] items = this.items; final Object[] items = this.items;
@SuppressWarnings("unchecked") E x = (E) items[takeIndex]; @SuppressWarnings("unchecked")
E x = (E) items[takeIndex];
items[takeIndex] = null; items[takeIndex] = null;
takeIndex = inc(takeIndex); takeIndex = inc(takeIndex);
count--; count--;
...@@ -396,7 +397,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -396,7 +397,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock; final ReentrantLock lock = this.lock;
lock.lock(); lock.lock();
try { try {
return (count == 0) ? null : itemAt(takeIndex); return itemAt(takeIndex); // null when queue is empty
} finally { } finally {
lock.unlock(); lock.unlock();
} }
...@@ -529,8 +530,13 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -529,8 +530,13 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
try { try {
final int count = this.count; final int count = this.count;
Object[] a = new Object[count]; Object[] a = new Object[count];
for (int i = takeIndex, k = 0; k < count; i = inc(i), k++) int n = items.length - takeIndex;
a[k] = items[i]; if (count <= n) {
System.arraycopy(items, takeIndex, a, 0, count);
} else {
System.arraycopy(items, takeIndex, a, 0, n);
System.arraycopy(items, 0, a, n, count - n);
}
return a; return a;
} finally { } finally {
lock.unlock(); lock.unlock();
...@@ -583,8 +589,13 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -583,8 +589,13 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
if (len < count) if (len < count)
a = (T[])java.lang.reflect.Array.newInstance( a = (T[])java.lang.reflect.Array.newInstance(
a.getClass().getComponentType(), count); a.getClass().getComponentType(), count);
for (int i = takeIndex, k = 0; k < count; i = inc(i), k++) int n = items.length - takeIndex;
a[k] = (T) items[i]; if (count <= n)
System.arraycopy(items, takeIndex, a, 0, count);
else {
System.arraycopy(items, takeIndex, a, 0, n);
System.arraycopy(items, 0, a, n, count - n);
}
if (len > count) if (len > count)
a[count] = null; a[count] = null;
return a; return a;
...@@ -674,7 +685,8 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E> ...@@ -674,7 +685,8 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
int i = 0; int i = 0;
try { try {
while (i < n) { while (i < n) {
@SuppressWarnings("unchecked") E x = (E) items[take]; @SuppressWarnings("unchecked")
E x = (E) items[take];
c.add(x); c.add(x);
items[take] = null; items[take] = null;
take = inc(take); take = inc(take);
......
...@@ -12,11 +12,11 @@ import java.util.*; ...@@ -12,11 +12,11 @@ import java.util.*;
* for the deque to become non-empty when retrieving an element, and wait for * 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. * 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 * of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future: * satisfied at some point in the future:
* one throws an exception, the second returns a special value (either * 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, * blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving * and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table: * up. These methods are summarized in the following table:
...@@ -87,20 +87,20 @@ import java.util.*; ...@@ -87,20 +87,20 @@ import java.util.*;
* </tr> * </tr>
* </table> * </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 * does not permit null elements, and may (or may not) be
* capacity-constrained. * capacity-constrained.
* *
* <p>A <tt>BlockingDeque</tt> implementation may be used directly as a FIFO * <p>A {@code BlockingDeque} implementation may be used directly as a FIFO
* <tt>BlockingQueue</tt>. The methods inherited from the * {@code BlockingQueue}. The methods inherited from the
* <tt>BlockingQueue</tt> interface are precisely equivalent to * {@code BlockingQueue} interface are precisely equivalent to
* <tt>BlockingDeque</tt> methods as indicated in the following table: * {@code BlockingDeque} methods as indicated in the following table:
* *
* <p> * <p>
* <table BORDER CELLPADDING=3 CELLSPACING=1> * <table BORDER CELLPADDING=3 CELLSPACING=1>
* <tr> * <tr>
* <td ALIGN=CENTER> <b><tt>BlockingQueue</tt> Method</b></td> * <td ALIGN=CENTER> <b>{@code BlockingQueue} Method</b></td>
* <td ALIGN=CENTER> <b>Equivalent <tt>BlockingDeque</tt> Method</b></td> * <td ALIGN=CENTER> <b>Equivalent {@code BlockingDeque} Method</b></td>
* </tr> * </tr>
* <tr> * <tr>
* <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td> * <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
...@@ -179,7 +179,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -179,7 +179,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the front of this deque if it is * Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions, * 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 * available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerFirst(Object) offerFirst}. * preferable to use {@link #offerFirst(Object) offerFirst}.
* *
...@@ -194,7 +194,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -194,7 +194,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the end of this deque if it is * Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions, * 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 * available. When using a capacity-restricted deque, it is generally
* preferable to use {@link #offerLast(Object) offerLast}. * preferable to use {@link #offerLast(Object) offerLast}.
* *
...@@ -209,7 +209,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -209,7 +209,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Inserts the specified element at the front of this deque if it is * Inserts the specified element at the front of this deque if it is
* possible to do so immediately without violating capacity restrictions, * 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. * currently available.
* When using a capacity-restricted deque, this method is generally * When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addFirst(Object) addFirst} method, which can * preferable to the {@link #addFirst(Object) addFirst} method, which can
...@@ -225,7 +225,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -225,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 * Inserts the specified element at the end of this deque if it is
* possible to do so immediately without violating capacity restrictions, * 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. * currently available.
* When using a capacity-restricted deque, this method is generally * When using a capacity-restricted deque, this method is generally
* preferable to the {@link #addLast(Object) addLast} method, which can * preferable to the {@link #addLast(Object) addLast} method, which can
...@@ -273,10 +273,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -273,10 +273,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -295,10 +295,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -295,10 +295,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -334,10 +334,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -334,10 +334,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available. * become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the head of this deque, or <tt>null</tt> if the specified * @return the head of this deque, or {@code null} if the specified
* waiting time elapses before an element is available * waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -350,10 +350,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -350,10 +350,10 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* become available. * become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the tail of this deque, or <tt>null</tt> if the specified * @return the tail of this deque, or {@code null} if the specified
* waiting time elapses before an element is available * waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -363,13 +363,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -363,13 +363,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Removes the first occurrence of the specified element from this deque. * Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the first element <tt>e</tt> such that * More formally, removes the first element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* @param o element to be removed from this deque, if present * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -381,13 +381,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -381,13 +381,13 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Removes the last occurrence of the specified element from this deque. * Removes the last occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the last element <tt>e</tt> such that * More formally, removes the last element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* @param o element to be removed from this deque, if present * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -402,8 +402,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -402,8 +402,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque * 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 * (in other words, at the tail of this deque) if it is possible to do so
* immediately without violating capacity restrictions, returning * immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and throwing an * {@code true} upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available. * {@code IllegalStateException} if no space is currently available.
* When using a capacity-restricted deque, it is generally preferable to * When using a capacity-restricted deque, it is generally preferable to
* use {@link #offer(Object) offer}. * use {@link #offer(Object) offer}.
* *
...@@ -423,7 +423,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -423,7 +423,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* Inserts the specified element into the queue represented by this deque * 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 * (in other words, at the tail of this deque) if it is possible to do so
* immediately without violating capacity restrictions, returning * 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 * available. When using a capacity-restricted deque, this method is
* generally preferable to the {@link #add} method, which can fail to * generally preferable to the {@link #add} method, which can fail to
* insert an element only by throwing an exception. * insert an element only by throwing an exception.
...@@ -465,8 +465,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -465,8 +465,8 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* {@link #offerLast(Object,long,TimeUnit) offerLast}. * {@link #offerLast(Object,long,TimeUnit) offerLast}.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> if the element was added to this deque, else * @return {@code true} if the element was added to this deque, else
* <tt>false</tt> * {@code false}
* @throws InterruptedException {@inheritDoc} * @throws InterruptedException {@inheritDoc}
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* prevents it from being added to this deque * prevents it from being added to this deque
...@@ -493,11 +493,11 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -493,11 +493,11 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Retrieves and removes the head of the queue represented by this deque * Retrieves and removes the head of the queue represented by this deque
* (in other words, the first element of this deque), or returns * (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()}. * <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(); E poll();
...@@ -521,7 +521,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -521,7 +521,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* <p>This method is equivalent to * <p>This method is equivalent to
* {@link #pollFirst(long,TimeUnit) pollFirst}. * {@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 * specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -544,27 +544,27 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -544,27 +544,27 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
/** /**
* Retrieves, but does not remove, the head of the queue represented by * Retrieves, but does not remove, the head of the queue represented by
* this deque (in other words, the first element of this deque), or * 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}. * <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(); E peek();
/** /**
* Removes the first occurrence of the specified element from this deque. * Removes the first occurrence of the specified element from this deque.
* If the deque does not contain the element, it is unchanged. * If the deque does not contain the element, it is unchanged.
* More formally, removes the first element <tt>e</tt> such that * More formally, removes the first element {@code e} such that
* <tt>o.equals(e)</tt> (if such an element exists). * {@code o.equals(e)} (if such an element exists).
* Returns <tt>true</tt> if this deque contained the specified element * Returns {@code true} if this deque contained the specified element
* (or equivalently, if this deque changed as a result of the call). * (or equivalently, if this deque changed as a result of the call).
* *
* <p>This method is equivalent to * <p>This method is equivalent to
* {@link #removeFirstOccurrence(Object) removeFirstOccurrence}. * {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
* *
* @param o element to be removed from this deque, if present * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -574,12 +574,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { ...@@ -574,12 +574,12 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
boolean remove(Object o); boolean remove(Object o);
/** /**
* Returns <tt>true</tt> if this deque contains the specified element. * Returns {@code true} if this deque contains the specified element.
* More formally, returns <tt>true</tt> if and only if this deque contains * More formally, returns {@code true} if and only if this deque contains
* at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * at least one element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this deque * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this deque * is incompatible with this deque
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
......
...@@ -19,11 +19,11 @@ import java.util.Queue; ...@@ -19,11 +19,11 @@ import java.util.Queue;
* element, and wait for space to become available in the queue when * element, and wait for space to become available in the queue when
* storing an element. * 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 * of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future: * satisfied at some point in the future:
* one throws an exception, the second returns a special value (either * 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, * blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving * and the fourth blocks for only a given maximum time limit before giving
* up. These methods are summarized in the following table: * up. These methods are summarized in the following table:
...@@ -60,37 +60,37 @@ import java.util.Queue; ...@@ -60,37 +60,37 @@ import java.util.Queue;
* </tr> * </tr>
* </table> * </table>
* *
* <p>A <tt>BlockingQueue</tt> does not accept <tt>null</tt> elements. * <p>A {@code BlockingQueue} does not accept {@code null} elements.
* Implementations throw <tt>NullPointerException</tt> on attempts * Implementations throw {@code NullPointerException} on attempts
* to <tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>. A * to {@code add}, {@code put} or {@code offer} a {@code null}. A
* <tt>null</tt> is used as a sentinel value to indicate failure of * {@code null} is used as a sentinel value to indicate failure of
* <tt>poll</tt> operations. * {@code poll} operations.
* *
* <p>A <tt>BlockingQueue</tt> may be capacity bounded. At any given * <p>A {@code BlockingQueue} may be capacity bounded. At any given
* time it may have a <tt>remainingCapacity</tt> beyond which no * time it may have a {@code remainingCapacity} beyond which no
* additional elements can be <tt>put</tt> without blocking. * additional elements can be {@code put} without blocking.
* A <tt>BlockingQueue</tt> without any intrinsic capacity constraints always * A {@code BlockingQueue} without any intrinsic capacity constraints always
* reports a remaining capacity of <tt>Integer.MAX_VALUE</tt>. * 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 * primarily for producer-consumer queues, but additionally support
* the {@link java.util.Collection} interface. So, for example, it is * the {@link java.util.Collection} interface. So, for example, it is
* possible to remove an arbitrary element from a queue using * 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 * <em>not</em> performed very efficiently, and are intended for only
* occasional use, such as when a queued message is cancelled. * 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 * queuing methods achieve their effects atomically using internal
* locks or other forms of concurrency control. However, the * locks or other forms of concurrency control. However, the
* <em>bulk</em> Collection operations <tt>addAll</tt>, * <em>bulk</em> Collection operations {@code addAll},
* <tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt> are * {@code containsAll}, {@code retainAll} and {@code removeAll} are
* <em>not</em> necessarily performed atomically unless specified * <em>not</em> necessarily performed atomically unless specified
* otherwise in an implementation. So it is possible, for example, for * otherwise in an implementation. So it is possible, for example, for
* <tt>addAll(c)</tt> to fail (throwing an exception) after adding * {@code addAll(c)} to fail (throwing an exception) after adding
* only some of the elements in <tt>c</tt>. * 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 &quot;close&quot; or &quot;shutdown&quot; operation to * any kind of &quot;close&quot; or &quot;shutdown&quot; operation to
* indicate that no more items will be added. The needs and usage of * indicate that no more items will be added. The needs and usage of
* such features tend to be implementation-dependent. For example, a * such features tend to be implementation-dependent. For example, a
...@@ -100,7 +100,7 @@ import java.util.Queue; ...@@ -100,7 +100,7 @@ import java.util.Queue;
* *
* <p> * <p>
* Usage example, based on a typical producer-consumer scenario. * 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. * producers and multiple consumers.
* <pre> {@code * <pre> {@code
* class Producer implements Runnable { * class Producer implements Runnable {
...@@ -152,13 +152,13 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -152,13 +152,13 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Inserts the specified element into this queue if it is possible to do * Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions, returning * so immediately without violating capacity restrictions, returning
* <tt>true</tt> upon success and throwing an * {@code true} upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available. * {@code IllegalStateException} if no space is currently available.
* When using a capacity-restricted queue, it is generally preferable to * When using a capacity-restricted queue, it is generally preferable to
* use {@link #offer(Object) offer}. * use {@link #offer(Object) offer}.
* *
* @param e the element to add * @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 * @throws IllegalStateException if the element cannot be added at this
* time due to capacity restrictions * time due to capacity restrictions
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -172,14 +172,14 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -172,14 +172,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Inserts the specified element into this queue if it is possible to do * Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions, returning * 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 * available. When using a capacity-restricted queue, this method is
* generally preferable to {@link #add}, which can fail to insert an * generally preferable to {@link #add}, which can fail to insert an
* element only by throwing an exception. * element only by throwing an exception.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> if the element was added to this queue, else * @return {@code true} if the element was added to this queue, else
* <tt>false</tt> * {@code false}
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue * prevents it from being added to this queue
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
...@@ -208,10 +208,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -208,10 +208,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* *
* @param e the element to add * @param e the element to add
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return <tt>true</tt> if successful, or <tt>false</tt> if * @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available * the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element * @throws ClassCastException if the class of the specified element
...@@ -237,10 +237,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -237,10 +237,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* specified wait time if necessary for an element to become available. * specified wait time if necessary for an element to become available.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the head of this queue, or <tt>null</tt> if the * @return the head of this queue, or {@code null} if the
* specified waiting time elapses before an element is available * specified waiting time elapses before an element is available
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
...@@ -250,11 +250,11 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -250,11 +250,11 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Returns the number of additional elements that this queue can ideally * Returns the number of additional elements that this queue can ideally
* (in the absence of memory or resource constraints) accept without * (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. * limit.
* *
* <p>Note that you <em>cannot</em> always tell if an attempt to insert * <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 * because it may be the case that another thread is about to
* insert or remove an element. * insert or remove an element.
* *
...@@ -264,14 +264,14 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -264,14 +264,14 @@ public interface BlockingQueue<E> extends Queue<E> {
/** /**
* Removes a single instance of the specified element from this queue, * Removes a single instance of the specified element from this queue,
* if it is present. More formally, removes an element <tt>e</tt> such * if it is present. More formally, removes an element {@code e} such
* that <tt>o.equals(e)</tt>, if this queue contains one or more such * that {@code o.equals(e)}, if this queue contains one or more such
* elements. * 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). * (or equivalently, if this queue changed as a result of the call).
* *
* @param o element to be removed from this queue, if present * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this queue * is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -281,12 +281,12 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -281,12 +281,12 @@ public interface BlockingQueue<E> extends Queue<E> {
boolean remove(Object o); boolean remove(Object o);
/** /**
* Returns <tt>true</tt> if this queue contains the specified element. * Returns {@code true} if this queue contains the specified element.
* More formally, returns <tt>true</tt> if and only if this queue contains * More formally, returns {@code true} if and only if this queue contains
* at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * at least one element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this queue * @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 * @throws ClassCastException if the class of the specified element
* is incompatible with this queue * is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>) * (<a href="../Collection.html#optional-restrictions">optional</a>)
...@@ -300,10 +300,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -300,10 +300,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* to the given collection. This operation may be more * to the given collection. This operation may be more
* efficient than repeatedly polling this queue. A failure * efficient than repeatedly polling this queue. A failure
* encountered while attempting to add elements to * 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 * either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in * 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 * this operation is undefined if the specified collection is
* modified while the operation is in progress. * modified while the operation is in progress.
* *
...@@ -324,10 +324,10 @@ public interface BlockingQueue<E> extends Queue<E> { ...@@ -324,10 +324,10 @@ public interface BlockingQueue<E> extends Queue<E> {
* Removes at most the given number of available elements from * Removes at most the given number of available elements from
* this queue and adds them to the given collection. A failure * this queue and adds them to the given collection. A failure
* encountered while attempting to add elements to * 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 * either or both collections when the associated exception is
* thrown. Attempts to drain a queue to itself result in * 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 * this operation is undefined if the specified collection is
* modified while the operation is in progress. * modified while the operation is in progress.
* *
......
...@@ -15,19 +15,18 @@ package java.util.concurrent; ...@@ -15,19 +15,18 @@ package java.util.concurrent;
* *
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
*
*/ */
public class BrokenBarrierException extends Exception { public class BrokenBarrierException extends Exception {
private static final long serialVersionUID = 7117394618823254244L; private static final long serialVersionUID = 7117394618823254244L;
/** /**
* Constructs a <tt>BrokenBarrierException</tt> with no specified detail * Constructs a {@code BrokenBarrierException} with no specified detail
* message. * message.
*/ */
public BrokenBarrierException() {} public BrokenBarrierException() {}
/** /**
* Constructs a <tt>BrokenBarrierException</tt> with the specified * Constructs a {@code BrokenBarrierException} with the specified
* detail message. * detail message.
* *
* @param message the detail message * @param message the detail message
......
...@@ -9,21 +9,21 @@ package java.util.concurrent; ...@@ -9,21 +9,21 @@ package java.util.concurrent;
/** /**
* A task that returns a result and may throw an exception. * A task that returns a result and may throw an exception.
* Implementors define a single method with no arguments called * Implementors define a single method with no arguments called
* <tt>call</tt>. * {@code call}.
* *
* <p>The <tt>Callable</tt> interface is similar to {@link * <p>The {@code Callable} interface is similar to {@link
* java.lang.Runnable}, in that both are designed for classes whose * java.lang.Runnable}, in that both are designed for classes whose
* instances are potentially executed by another thread. A * instances are potentially executed by another thread. A
* <tt>Runnable</tt>, however, does not return a result and cannot * {@code Runnable}, however, does not return a result and cannot
* throw a checked exception. * throw a checked exception.
* *
* <p> The {@link Executors} class contains utility methods to * <p>The {@link Executors} class contains utility methods to
* convert from other common forms to <tt>Callable</tt> classes. * convert from other common forms to {@code Callable} classes.
* *
* @see Executor * @see Executor
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
* @param <V> the result type of method <tt>call</tt> * @param <V> the result type of method {@code call}
*/ */
public interface Callable<V> { public interface Callable<V> {
/** /**
......
...@@ -18,12 +18,12 @@ public class CancellationException extends IllegalStateException { ...@@ -18,12 +18,12 @@ public class CancellationException extends IllegalStateException {
private static final long serialVersionUID = -9202173006928992231L; private static final long serialVersionUID = -9202173006928992231L;
/** /**
* Constructs a <tt>CancellationException</tt> with no detail message. * Constructs a {@code CancellationException} with no detail message.
*/ */
public CancellationException() {} public CancellationException() {}
/** /**
* Constructs a <tt>CancellationException</tt> with the specified detail * Constructs a {@code CancellationException} with the specified detail
* message. * message.
* *
* @param message the detail message * @param message the detail message
......
...@@ -9,17 +9,17 @@ package java.util.concurrent; ...@@ -9,17 +9,17 @@ package java.util.concurrent;
/** /**
* A service that decouples the production of new asynchronous tasks * A service that decouples the production of new asynchronous tasks
* from the consumption of the results of completed tasks. Producers * from the consumption of the results of completed tasks. Producers
* <tt>submit</tt> tasks for execution. Consumers <tt>take</tt> * {@code submit} tasks for execution. Consumers {@code take}
* completed tasks and process their results in the order they * completed tasks and process their results in the order they
* complete. A <tt>CompletionService</tt> can for example be used to * complete. A {@code CompletionService} can for example be used to
* manage asynchronous IO, in which tasks that perform reads are * manage asynchronous I/O, in which tasks that perform reads are
* submitted in one part of a program or system, and then acted upon * submitted in one part of a program or system, and then acted upon
* in a different part of the program when the reads complete, * in a different part of the program when the reads complete,
* possibly in a different order than they were requested. * possibly in a different order than they were requested.
* *
* <p>Typically, a <tt>CompletionService</tt> relies on a separate * <p>Typically, a {@code CompletionService} relies on a separate
* {@link Executor} to actually execute the tasks, in which case the * {@link Executor} to actually execute the tasks, in which case the
* <tt>CompletionService</tt> only manages an internal completion * {@code CompletionService} only manages an internal completion
* queue. The {@link ExecutorCompletionService} class provides an * queue. The {@link ExecutorCompletionService} class provides an
* implementation of this approach. * implementation of this approach.
* *
...@@ -28,7 +28,6 @@ package java.util.concurrent; ...@@ -28,7 +28,6 @@ package java.util.concurrent;
* <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a> * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
* actions taken by that task, which in turn <i>happen-before</i> * actions taken by that task, which in turn <i>happen-before</i>
* actions following a successful return from the corresponding {@code take()}. * actions following a successful return from the corresponding {@code take()}.
*
*/ */
public interface CompletionService<V> { public interface CompletionService<V> {
/** /**
...@@ -52,7 +51,7 @@ public interface CompletionService<V> { ...@@ -52,7 +51,7 @@ public interface CompletionService<V> {
* @param task the task to submit * @param task the task to submit
* @param result the result to return upon successful completion * @param result the result to return upon successful completion
* @return a Future representing pending completion of the task, * @return a Future representing pending completion of the task,
* and whose <tt>get()</tt> method will return the given * and whose {@code get()} method will return the given
* result value upon completion * result value upon completion
* @throws RejectedExecutionException if the task cannot be * @throws RejectedExecutionException if the task cannot be
* scheduled for execution * scheduled for execution
...@@ -69,13 +68,12 @@ public interface CompletionService<V> { ...@@ -69,13 +68,12 @@ public interface CompletionService<V> {
*/ */
Future<V> take() throws InterruptedException; Future<V> take() throws InterruptedException;
/** /**
* Retrieves and removes the Future representing the next * Retrieves and removes the Future representing the next
* completed task or <tt>null</tt> if none are present. * completed task, or {@code null} if none are present.
* *
* @return the Future representing the next completed task, or * @return the Future representing the next completed task, or
* <tt>null</tt> if none are present * {@code null} if none are present
*/ */
Future<V> poll(); Future<V> poll();
...@@ -85,11 +83,11 @@ public interface CompletionService<V> { ...@@ -85,11 +83,11 @@ public interface CompletionService<V> {
* time if none are yet present. * time if none are yet present.
* *
* @param timeout how long to wait before giving up, in units of * @param timeout how long to wait before giving up, in units of
* <tt>unit</tt> * {@code unit}
* @param unit a <tt>TimeUnit</tt> determining how to interpret the * @param unit a {@code TimeUnit} determining how to interpret the
* <tt>timeout</tt> parameter * {@code timeout} parameter
* @return the Future representing the next completed task or * @return the Future representing the next completed task or
* <tt>null</tt> if the specified waiting time elapses * {@code null} if the specified waiting time elapses
* before one is present * before one is present
* @throws InterruptedException if interrupted while waiting * @throws InterruptedException if interrupted while waiting
*/ */
......
...@@ -63,7 +63,6 @@ import java.util.Queue; ...@@ -63,7 +63,6 @@ import java.util.Queue;
* @author Martin Buchholz * @author Martin Buchholz
* @param <E> the type of elements held in this collection * @param <E> the type of elements held in this collection
*/ */
public class ConcurrentLinkedDeque<E> public class ConcurrentLinkedDeque<E>
extends AbstractCollection<E> extends AbstractCollection<E>
implements Deque<E>, java.io.Serializable { implements Deque<E>, java.io.Serializable {
...@@ -790,7 +789,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -790,7 +789,7 @@ public class ConcurrentLinkedDeque<E>
* Creates an array list and fills it with elements of this list. * Creates an array list and fills it with elements of this list.
* Used by toArray. * Used by toArray.
* *
* @return the arrayList * @return the array list
*/ */
private ArrayList<E> toArrayList() { private ArrayList<E> toArrayList() {
ArrayList<E> list = new ArrayList<E>(); ArrayList<E> list = new ArrayList<E>();
...@@ -1360,11 +1359,10 @@ public class ConcurrentLinkedDeque<E> ...@@ -1360,11 +1359,10 @@ public class ConcurrentLinkedDeque<E>
} }
/** /**
* Saves the state to a stream (that is, serializes it). * Saves this deque to a stream (that is, serializes it).
* *
* @serialData All of the elements (each an {@code E}) in * @serialData All of the elements (each an {@code E}) in
* the proper order, followed by a null * the proper order, followed by a null
* @param s the stream
*/ */
private void writeObject(java.io.ObjectOutputStream s) private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException { throws java.io.IOException {
...@@ -1384,8 +1382,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -1384,8 +1382,7 @@ public class ConcurrentLinkedDeque<E>
} }
/** /**
* Reconstitutes the instance from a stream (that is, deserializes it). * Reconstitutes this deque from a stream (that is, deserializes it).
* @param s the stream
*/ */
private void readObject(java.io.ObjectInputStream s) private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException { throws java.io.IOException, ClassNotFoundException {
...@@ -1408,7 +1405,6 @@ public class ConcurrentLinkedDeque<E> ...@@ -1408,7 +1405,6 @@ public class ConcurrentLinkedDeque<E>
initHeadTail(h, t); initHeadTail(h, t);
} }
private boolean casHead(Node<E> cmp, Node<E> val) { private boolean casHead(Node<E> cmp, Node<E> val) {
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val); return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
} }
......
...@@ -69,7 +69,6 @@ import java.util.Queue; ...@@ -69,7 +69,6 @@ import java.util.Queue;
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
* @param <E> the type of elements held in this collection * @param <E> the type of elements held in this collection
*
*/ */
public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
implements Queue<E>, java.io.Serializable { implements Queue<E>, java.io.Serializable {
...@@ -218,7 +217,6 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -218,7 +217,6 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
*/ */
private transient volatile Node<E> tail; private transient volatile Node<E> tail;
/** /**
* Creates a {@code ConcurrentLinkedQueue} that is initially empty. * Creates a {@code ConcurrentLinkedQueue} that is initially empty.
*/ */
...@@ -268,7 +266,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -268,7 +266,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
} }
/** /**
* Try to CAS head to p. If successful, repoint old head to itself * Tries to CAS head to p. If successful, repoint old head to itself
* as sentinel for succ(), below. * as sentinel for succ(), below.
*/ */
final void updateHead(Node<E> h, Node<E> p) { final void updateHead(Node<E> h, Node<E> p) {
...@@ -717,11 +715,10 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -717,11 +715,10 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
} }
/** /**
* Saves the state to a stream (that is, serializes it). * Saves this queue to a stream (that is, serializes it).
* *
* @serialData All of the elements (each an {@code E}) in * @serialData All of the elements (each an {@code E}) in
* the proper order, followed by a null * the proper order, followed by a null
* @param s the stream
*/ */
private void writeObject(java.io.ObjectOutputStream s) private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException { throws java.io.IOException {
...@@ -741,8 +738,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -741,8 +738,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
} }
/** /**
* Reconstitutes the instance from a stream (that is, deserializes it). * Reconstitutes this queue from a stream (that is, deserializes it).
* @param s the stream
*/ */
private void readObject(java.io.ObjectInputStream s) private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException { throws java.io.IOException, ClassNotFoundException {
......
...@@ -13,7 +13,7 @@ import java.util.Map; ...@@ -13,7 +13,7 @@ import java.util.Map;
/** /**
* A {@link java.util.Map} providing additional atomic * A {@link java.util.Map} providing additional atomic
* <tt>putIfAbsent</tt>, <tt>remove</tt>, and <tt>replace</tt> methods. * {@code putIfAbsent}, {@code remove}, and {@code replace} methods.
* *
* <p>Memory consistency effects: As with other concurrent * <p>Memory consistency effects: As with other concurrent
* collections, actions in a thread prior to placing an object into a * collections, actions in a thread prior to placing an object into a
...@@ -27,7 +27,7 @@ import java.util.Map; ...@@ -27,7 +27,7 @@ import java.util.Map;
* @param <K> the type of keys maintained by this map * @param <K> the type of keys maintained by this map
* @param <V> the type of mapped values * @param <V> the type of mapped values
*/ */
public interface ConcurrentMap<K, V> extends Map<K, V> { public interface ConcurrentMap<K,V> extends Map<K,V> {
/** /**
* If the specified key is not already associated * If the specified key is not already associated
* with a value, associate it with the given value. * with a value, associate it with the given value.
...@@ -43,11 +43,11 @@ public interface ConcurrentMap<K, V> extends Map<K, V> { ...@@ -43,11 +43,11 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* @param key key with which the specified value is to be associated * @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key * @param value value to be associated with the specified key
* @return the previous value associated with the specified key, or * @return the previous value associated with the specified key, or
* <tt>null</tt> if there was no mapping for the key. * {@code null} if there was no mapping for the key.
* (A <tt>null</tt> return can also indicate that the map * (A {@code null} return can also indicate that the map
* previously associated <tt>null</tt> with the key, * previously associated {@code null} with the key,
* if the implementation supports null values.) * if the implementation supports null values.)
* @throws UnsupportedOperationException if the <tt>put</tt> operation * @throws UnsupportedOperationException if the {@code put} operation
* is not supported by this map * is not supported by this map
* @throws ClassCastException if the class of the specified key or value * @throws ClassCastException if the class of the specified key or value
* prevents it from being stored in this map * prevents it from being stored in this map
...@@ -55,7 +55,6 @@ public interface ConcurrentMap<K, V> extends Map<K, V> { ...@@ -55,7 +55,6 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* and this map does not permit null keys or values * and this map does not permit null keys or values
* @throws IllegalArgumentException if some property of the specified key * @throws IllegalArgumentException if some property of the specified key
* or value prevents it from being stored in this map * or value prevents it from being stored in this map
*
*/ */
V putIfAbsent(K key, V value); V putIfAbsent(K key, V value);
...@@ -73,8 +72,8 @@ public interface ConcurrentMap<K, V> extends Map<K, V> { ...@@ -73,8 +72,8 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* *
* @param key key with which the specified value is associated * @param key key with which the specified value is associated
* @param value value expected to be associated with the specified key * @param value value expected to be associated with the specified key
* @return <tt>true</tt> if the value was removed * @return {@code true} if the value was removed
* @throws UnsupportedOperationException if the <tt>remove</tt> operation * @throws UnsupportedOperationException if the {@code remove} operation
* is not supported by this map * is not supported by this map
* @throws ClassCastException if the key or value is of an inappropriate * @throws ClassCastException if the key or value is of an inappropriate
* type for this map * type for this map
...@@ -100,8 +99,8 @@ public interface ConcurrentMap<K, V> extends Map<K, V> { ...@@ -100,8 +99,8 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* @param key key with which the specified value is associated * @param key key with which the specified value is associated
* @param oldValue value expected to be associated with the specified key * @param oldValue value expected to be associated with the specified key
* @param newValue value to be associated with the specified key * @param newValue value to be associated with the specified key
* @return <tt>true</tt> if the value was replaced * @return {@code true} if the value was replaced
* @throws UnsupportedOperationException if the <tt>put</tt> operation * @throws UnsupportedOperationException if the {@code put} operation
* is not supported by this map * is not supported by this map
* @throws ClassCastException if the class of a specified key or value * @throws ClassCastException if the class of a specified key or value
* prevents it from being stored in this map * prevents it from being stored in this map
...@@ -126,11 +125,11 @@ public interface ConcurrentMap<K, V> extends Map<K, V> { ...@@ -126,11 +125,11 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* @param key key with which the specified value is associated * @param key key with which the specified value is associated
* @param value value to be associated with the specified key * @param value value to be associated with the specified key
* @return the previous value associated with the specified key, or * @return the previous value associated with the specified key, or
* <tt>null</tt> if there was no mapping for the key. * {@code null} if there was no mapping for the key.
* (A <tt>null</tt> return can also indicate that the map * (A {@code null} return can also indicate that the map
* previously associated <tt>null</tt> with the key, * previously associated {@code null} with the key,
* if the implementation supports null values.) * if the implementation supports null values.)
* @throws UnsupportedOperationException if the <tt>put</tt> operation * @throws UnsupportedOperationException if the {@code put} operation
* is not supported by this map * is not supported by this map
* @throws ClassCastException if the class of the specified key or value * @throws ClassCastException if the class of the specified key or value
* prevents it from being stored in this map * prevents it from being stored in this map
......
...@@ -38,7 +38,6 @@ public interface ConcurrentNavigableMap<K,V> ...@@ -38,7 +38,6 @@ public interface ConcurrentNavigableMap<K,V>
*/ */
ConcurrentNavigableMap<K,V> headMap(K toKey, boolean inclusive); ConcurrentNavigableMap<K,V> headMap(K toKey, boolean inclusive);
/** /**
* @throws ClassCastException {@inheritDoc} * @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
...@@ -73,7 +72,7 @@ public interface ConcurrentNavigableMap<K,V> ...@@ -73,7 +72,7 @@ public interface ConcurrentNavigableMap<K,V>
* reflected in the descending map, and vice-versa. * reflected in the descending map, and vice-versa.
* *
* <p>The returned map has an ordering equivalent to * <p>The returned map 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 m.descendingMap().descendingMap()} returns a * The expression {@code m.descendingMap().descendingMap()} returns a
* view of {@code m} essentially equivalent to {@code m}. * view of {@code m} essentially equivalent to {@code m}.
* *
......
...@@ -19,7 +19,7 @@ import java.util.*; ...@@ -19,7 +19,7 @@ import java.util.*;
* on which constructor is used. * on which constructor is used.
* *
* <p>This implementation provides expected average <i>log(n)</i> time * <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 and their variants. Insertion, removal, and access
* operations safely execute concurrently by multiple threads. * operations safely execute concurrently by multiple threads.
* Iterators are <i>weakly consistent</i>, returning elements * Iterators are <i>weakly consistent</i>, returning elements
...@@ -29,23 +29,23 @@ import java.util.*; ...@@ -29,23 +29,23 @@ import java.util.*;
* other operations. Ascending ordered views and their iterators are * other operations. Ascending ordered views and their iterators are
* faster than descending ones. * 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 * method is <em>not</em> a constant-time operation. Because of the
* asynchronous nature of these sets, determining the current number * asynchronous nature of these sets, determining the current number
* of elements requires a traversal of the elements, and so may report * of elements requires a traversal of the elements, and so may report
* inaccurate results if this collection is modified during traversal. * inaccurate results if this collection is modified during traversal.
* Additionally, the bulk operations <tt>addAll</tt>, * Additionally, the bulk operations {@code addAll},
* <tt>removeAll</tt>, <tt>retainAll</tt>, <tt>containsAll</tt>, * {@code removeAll}, {@code retainAll}, {@code containsAll},
* <tt>equals</tt>, and <tt>toArray</tt> are <em>not</em> guaranteed * {@code equals}, and {@code toArray} are <em>not</em> guaranteed
* to be performed atomically. For example, an iterator operating * 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. * of the added elements.
* *
* <p>This class and its iterators implement all of the * <p>This class and its iterators implement all of the
* <em>optional</em> methods of the {@link Set} and {@link Iterator} * <em>optional</em> methods of the {@link Set} and {@link Iterator}
* interfaces. Like most other concurrent collection implementations, * interfaces. Like most other concurrent collection implementations,
* this class does not permit the use of <tt>null</tt> elements, * this class does not permit the use of {@code null} elements,
* because <tt>null</tt> arguments and return values cannot be reliably * because {@code null} arguments and return values cannot be reliably
* distinguished from the absence of elements. * distinguished from the absence of elements.
* *
* @author Doug Lea * @author Doug Lea
...@@ -61,7 +61,7 @@ public class ConcurrentSkipListSet<E> ...@@ -61,7 +61,7 @@ public class ConcurrentSkipListSet<E>
/** /**
* The underlying map. Uses Boolean.TRUE as value for each * The underlying map. Uses Boolean.TRUE as value for each
* element. This field is declared final for the sake of thread * 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; private final ConcurrentNavigableMap<E,Object> m;
...@@ -78,7 +78,7 @@ public class ConcurrentSkipListSet<E> ...@@ -78,7 +78,7 @@ public class ConcurrentSkipListSet<E>
* the specified comparator. * the specified comparator.
* *
* @param comparator the comparator that will be used to order this set. * @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. * ordering} of the elements will be used.
*/ */
public ConcurrentSkipListSet(Comparator<? super E> comparator) { public ConcurrentSkipListSet(Comparator<? super E> comparator) {
...@@ -91,7 +91,7 @@ public class ConcurrentSkipListSet<E> ...@@ -91,7 +91,7 @@ public class ConcurrentSkipListSet<E>
* {@linkplain Comparable natural ordering}. * {@linkplain Comparable natural ordering}.
* *
* @param c The elements that will comprise the new set * @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 * not {@link Comparable}, or are not mutually comparable
* @throws NullPointerException if the specified collection or any * @throws NullPointerException if the specified collection or any
* of its elements are null * of its elements are null
...@@ -122,7 +122,7 @@ public class ConcurrentSkipListSet<E> ...@@ -122,7 +122,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.) * instance. (The elements themselves are not cloned.)
* *
* @return a shallow copy of this set * @return a shallow copy of this set
...@@ -143,8 +143,8 @@ public class ConcurrentSkipListSet<E> ...@@ -143,8 +143,8 @@ public class ConcurrentSkipListSet<E>
/** /**
* Returns the number of elements in this set. If this set * Returns the number of elements in this set. If this set
* contains more than <tt>Integer.MAX_VALUE</tt> elements, it * contains more than {@code Integer.MAX_VALUE} elements, it
* returns <tt>Integer.MAX_VALUE</tt>. * returns {@code Integer.MAX_VALUE}.
* *
* <p>Beware that, unlike in most collections, this method is * <p>Beware that, unlike in most collections, this method is
* <em>NOT</em> a constant-time operation. Because of the * <em>NOT</em> a constant-time operation. Because of the
...@@ -162,20 +162,20 @@ public class ConcurrentSkipListSet<E> ...@@ -162,20 +162,20 @@ public class ConcurrentSkipListSet<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() { public boolean isEmpty() {
return m.isEmpty(); return m.isEmpty();
} }
/** /**
* Returns <tt>true</tt> if this set contains the specified element. * Returns {@code true} if this set contains the specified element.
* More formally, returns <tt>true</tt> if and only if this set * More formally, returns {@code true} if and only if this set
* contains an element <tt>e</tt> such that <tt>o.equals(e)</tt>. * contains an element {@code e} such that {@code o.equals(e)}.
* *
* @param o object to be checked for containment in this set * @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 * @throws ClassCastException if the specified element cannot be
* compared with the elements currently in this set * compared with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
...@@ -186,15 +186,15 @@ public class ConcurrentSkipListSet<E> ...@@ -186,15 +186,15 @@ public class ConcurrentSkipListSet<E>
/** /**
* Adds the specified element to this set if it is not already present. * 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 * More formally, adds the specified element {@code e} to this set if
* the set contains no element <tt>e2</tt> such that <tt>e.equals(e2)</tt>. * 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 * 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 * @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 * 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 * with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
...@@ -204,15 +204,15 @@ public class ConcurrentSkipListSet<E> ...@@ -204,15 +204,15 @@ public class ConcurrentSkipListSet<E>
/** /**
* Removes the specified element from this set if it is present. * 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.equals(e)</tt>, if this set contains such an element. * {@code o.equals(e)}, if this set contains such an element.
* Returns <tt>true</tt> if this set contained the element (or * Returns {@code true} if this set contained the element (or
* equivalently, if this set changed as a result of the call). * equivalently, if this set changed as a result of the call).
* (This set will not contain the element once the call returns.) * (This set will not contain the element once the call returns.)
* *
* @param o object to be removed from this set, if present * @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
* @throws ClassCastException if <tt>o</tt> cannot be compared * @throws ClassCastException if {@code o} cannot be compared
* with the elements currently in this set * with the elements currently in this set
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
...@@ -250,7 +250,7 @@ public class ConcurrentSkipListSet<E> ...@@ -250,7 +250,7 @@ public class ConcurrentSkipListSet<E>
/** /**
* Compares the specified object with this set for equality. Returns * 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 * 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 this set (or equivalently, every member of this set is
* contained in the specified set). This definition ensures that the * contained in the specified set). This definition ensures that the
...@@ -258,7 +258,7 @@ public class ConcurrentSkipListSet<E> ...@@ -258,7 +258,7 @@ public class ConcurrentSkipListSet<E>
* set interface. * set interface.
* *
* @param o the object to be compared for equality with this set * @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) { public boolean equals(Object o) {
// Override AbstractSet version to avoid calling size() // Override AbstractSet version to avoid calling size()
...@@ -269,7 +269,7 @@ public class ConcurrentSkipListSet<E> ...@@ -269,7 +269,7 @@ public class ConcurrentSkipListSet<E>
Collection<?> c = (Collection<?>) o; Collection<?> c = (Collection<?>) o;
try { try {
return containsAll(c) && c.containsAll(this); return containsAll(c) && c.containsAll(this);
} catch (ClassCastException unused) { } catch (ClassCastException unused) {
return false; return false;
} catch (NullPointerException unused) { } catch (NullPointerException unused) {
return false; return false;
...@@ -283,7 +283,7 @@ public class ConcurrentSkipListSet<E> ...@@ -283,7 +283,7 @@ public class ConcurrentSkipListSet<E>
* value is the <i>asymmetric set difference</i> of the two sets. * value is the <i>asymmetric set difference</i> of the two sets.
* *
* @param c collection containing elements to be removed from this set * @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 * @throws ClassCastException if the types of one or more elements in this
* set are incompatible with the specified collection * set are incompatible with the specified collection
* @throws NullPointerException if the specified collection or any * @throws NullPointerException if the specified collection or any
...@@ -431,7 +431,7 @@ public class ConcurrentSkipListSet<E> ...@@ -431,7 +431,7 @@ public class ConcurrentSkipListSet<E>
* reflected in the descending set, and vice-versa. * reflected in the descending set, and vice-versa.
* *
* <p>The returned set has an ordering equivalent to * <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 * The expression {@code s.descendingSet().descendingSet()} returns a
* view of {@code s} essentially equivalent to {@code s}. * view of {@code s} essentially equivalent to {@code s}.
* *
......
...@@ -20,17 +20,17 @@ import java.util.*; ...@@ -20,17 +20,17 @@ import java.util.*;
* vastly outnumber mutative operations, and you need * vastly outnumber mutative operations, and you need
* to prevent interference among threads during traversal. * to prevent interference among threads during traversal.
* <li>It is thread-safe. * <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 * are expensive since they usually entail copying the entire underlying
* array. * 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 * <li>Traversal via iterators is fast and cannot encounter
* interference from other threads. Iterators rely on * interference from other threads. Iterators rely on
* unchanging snapshots of the array at the time the iterators were * unchanging snapshots of the array at the time the iterators were
* constructed. * constructed.
* </ul> * </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 * copy-on-write set to maintain a set of Handler objects that
* perform some action upon state updates. * perform some action upon state updates.
* *
...@@ -48,7 +48,7 @@ import java.util.*; ...@@ -48,7 +48,7 @@ import java.util.*;
* public void update() { * public void update() {
* changeState(); * changeState();
* for (Handler handler : handlers) * for (Handler handler : handlers)
* handler.handle(); * handler.handle();
* } * }
* }}</pre> * }}</pre>
* *
...@@ -92,22 +92,22 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -92,22 +92,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() { public boolean isEmpty() {
return al.isEmpty(); return al.isEmpty();
} }
/** /**
* Returns <tt>true</tt> if this set contains the specified element. * Returns {@code true} if this set contains the specified element.
* More formally, returns <tt>true</tt> if and only if this set * More formally, returns {@code true} if and only if this set
* contains an element <tt>e</tt> such that * contains an element {@code e} such that
* <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>. * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
* *
* @param o element whose presence in this set is to be tested * @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) { public boolean contains(Object o) {
return al.contains(o); return al.contains(o);
...@@ -143,7 +143,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -143,7 +143,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>If this set fits in the specified array with room to spare * <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 * (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 * 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 * set <i>only</i> if the caller knows that this set does not contain
* any null elements.) * any null elements.)
* *
...@@ -156,14 +156,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -156,14 +156,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* precise control over the runtime type of the output array, and may, * precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs. * 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 * 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> * <pre> {@code String[] y = x.toArray(new String[0]);}</pre>
* *
* Note that <tt>toArray(new Object[0])</tt> is identical in function to * Note that {@code toArray(new Object[0])} is identical in function to
* <tt>toArray()</tt>. * {@code toArray()}.
* *
* @param a the array into which the elements of this set are to be * @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 * stored, if it is big enough; otherwise, a new array of the same
...@@ -188,15 +188,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -188,15 +188,15 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Removes the specified element from this set if it is present. * 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&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;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 * this set contained the element (or equivalently, if this set
* changed as a result of the call). (This set will not contain the * changed as a result of the call). (This set will not contain the
* element once the call returns.) * element once the call returns.)
* *
* @param o object to be removed from this set, if present * @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) { public boolean remove(Object o) {
return al.remove(o); return al.remove(o);
...@@ -204,14 +204,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -204,14 +204,14 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Adds the specified element to this set if it is not already present. * 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 * More formally, adds the specified element {@code e} to this set if
* the set contains no element <tt>e2</tt> such that * the set contains no element {@code e2} such that
* <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>. * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
* If this set already contains the element, the call leaves the set * 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 * @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 * element
*/ */
public boolean add(E e) { public boolean add(E e) {
...@@ -219,12 +219,12 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -219,12 +219,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 * 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 * @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 * specified collection
* @throws NullPointerException if the specified collection is null * @throws NullPointerException if the specified collection is null
* @see #contains(Object) * @see #contains(Object)
...@@ -236,13 +236,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -236,13 +236,13 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
/** /**
* Adds all of the elements in the specified collection to this set if * 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 * 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 * 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 * this operation is undefined if the specified collection is modified
* while the operation is in progress. * while the operation is in progress.
* *
* @param c collection containing elements to be added to this set * @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 * @throws NullPointerException if the specified collection is null
* @see #add(Object) * @see #add(Object)
*/ */
...@@ -257,7 +257,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -257,7 +257,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <i>asymmetric set difference</i> of the two sets. * <i>asymmetric set difference</i> of the two sets.
* *
* @param c collection containing elements to be removed from this set * @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 * @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional) * is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the * @throws NullPointerException if this set contains a null element and the
...@@ -278,7 +278,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -278,7 +278,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* two sets. * two sets.
* *
* @param c collection containing elements to be retained in this set * @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 * @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection (optional) * is incompatible with the specified collection (optional)
* @throws NullPointerException if this set contains a null element and the * @throws NullPointerException if this set contains a null element and the
...@@ -297,7 +297,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -297,7 +297,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
* <p>The returned iterator provides a snapshot of the state of the set * <p>The returned iterator provides a snapshot of the state of the set
* when the iterator was constructed. No synchronization is needed while * when the iterator was constructed. No synchronization is needed while
* traversing the iterator. The iterator does <em>NOT</em> support the * 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 * @return an iterator over the elements in this set
*/ */
...@@ -354,7 +354,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E> ...@@ -354,7 +354,7 @@ public class CopyOnWriteArraySet<E> extends AbstractSet<E>
} }
/** /**
* Test for equality, coping with nulls. * Tests for equality, coping with nulls.
*/ */
private static boolean eq(Object o1, Object o2) { private static boolean eq(Object o1, Object o2) {
return (o1 == null) ? o2 == null : o1.equals(o2); return (o1 == null) ? o2 == null : o1.equals(o2);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
package java.util.concurrent; package java.util.concurrent;
import java.util.concurrent.locks.*; import java.util.concurrent.locks.AbstractQueuedSynchronizer;
/** /**
* A synchronization aid that allows one or more threads to wait until * A synchronization aid that allows one or more threads to wait until
...@@ -63,15 +63,15 @@ import java.util.concurrent.locks.*; ...@@ -63,15 +63,15 @@ import java.util.concurrent.locks.*;
* private final CountDownLatch startSignal; * private final CountDownLatch startSignal;
* private final CountDownLatch doneSignal; * private final CountDownLatch doneSignal;
* Worker(CountDownLatch startSignal, CountDownLatch doneSignal) { * Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
* this.startSignal = startSignal; * this.startSignal = startSignal;
* this.doneSignal = doneSignal; * this.doneSignal = doneSignal;
* } * }
* public void run() { * public void run() {
* try { * try {
* startSignal.await(); * startSignal.await();
* doWork(); * doWork();
* doneSignal.countDown(); * doneSignal.countDown();
* } catch (InterruptedException ex) {} // return; * } catch (InterruptedException ex) {} // return;
* } * }
* *
* void doWork() { ... } * void doWork() { ... }
...@@ -101,14 +101,14 @@ import java.util.concurrent.locks.*; ...@@ -101,14 +101,14 @@ import java.util.concurrent.locks.*;
* private final CountDownLatch doneSignal; * private final CountDownLatch doneSignal;
* private final int i; * private final int i;
* WorkerRunnable(CountDownLatch doneSignal, int i) { * WorkerRunnable(CountDownLatch doneSignal, int i) {
* this.doneSignal = doneSignal; * this.doneSignal = doneSignal;
* this.i = i; * this.i = i;
* } * }
* public void run() { * public void run() {
* try { * try {
* doWork(i); * doWork(i);
* doneSignal.countDown(); * doneSignal.countDown();
* } catch (InterruptedException ex) {} // return; * } catch (InterruptedException ex) {} // return;
* } * }
* *
* void doWork() { ... } * void doWork() { ... }
......
This diff is collapsed.
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
*/ */
package java.util.concurrent; package java.util.concurrent;
import java.util.concurrent.locks.*; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/** /**
* A synchronization aid that allows a set of threads to all wait for * A synchronization aid that allows a set of threads to all wait for
...@@ -15,7 +16,7 @@ import java.util.concurrent.locks.*; ...@@ -15,7 +16,7 @@ import java.util.concurrent.locks.*;
* <em>cyclic</em> because it can be re-used after the waiting threads * <em>cyclic</em> because it can be re-used after the waiting threads
* are released. * are released.
* *
* <p>A <tt>CyclicBarrier</tt> supports an optional {@link Runnable} command * <p>A {@code CyclicBarrier} supports an optional {@link Runnable} command
* that is run once per barrier point, after the last thread in the party * that is run once per barrier point, after the last thread in the party
* arrives, but before any threads are released. * arrives, but before any threads are released.
* This <em>barrier action</em> is useful * This <em>barrier action</em> is useful
...@@ -68,8 +69,8 @@ import java.util.concurrent.locks.*; ...@@ -68,8 +69,8 @@ import java.util.concurrent.locks.*;
* barrier until all rows have been processed. When all rows are processed * barrier until all rows have been processed. When all rows are processed
* the supplied {@link Runnable} barrier action is executed and merges the * the supplied {@link Runnable} barrier action is executed and merges the
* rows. If the merger * rows. If the merger
* determines that a solution has been found then <tt>done()</tt> will return * determines that a solution has been found then {@code done()} will return
* <tt>true</tt> and each worker will terminate. * {@code true} and each worker will terminate.
* *
* <p>If the barrier action does not rely on the parties being suspended when * <p>If the barrier action does not rely on the parties being suspended when
* it is executed, then any of the threads in the party could execute that * it is executed, then any of the threads in the party could execute that
...@@ -82,7 +83,7 @@ import java.util.concurrent.locks.*; ...@@ -82,7 +83,7 @@ import java.util.concurrent.locks.*;
* // log the completion of this iteration * // log the completion of this iteration
* }}</pre> * }}</pre>
* *
* <p>The <tt>CyclicBarrier</tt> uses an all-or-none breakage model * <p>The {@code CyclicBarrier} uses an all-or-none breakage model
* for failed synchronization attempts: If a thread leaves a barrier * for failed synchronization attempts: If a thread leaves a barrier
* point prematurely because of interruption, failure, or timeout, all * point prematurely because of interruption, failure, or timeout, all
* other threads waiting at that barrier point will also leave * other threads waiting at that barrier point will also leave
...@@ -109,7 +110,7 @@ public class CyclicBarrier { ...@@ -109,7 +110,7 @@ public class CyclicBarrier {
* is reset. There can be many generations associated with threads * is reset. There can be many generations associated with threads
* using the barrier - due to the non-deterministic way the lock * using the barrier - due to the non-deterministic way the lock
* may be allocated to waiting threads - but only one of these * may be allocated to waiting threads - but only one of these
* can be active at a time (the one to which <tt>count</tt> applies) * can be active at a time (the one to which {@code count} applies)
* and all the rest are either broken or tripped. * and all the rest are either broken or tripped.
* There need not be an active generation if there has been a break * There need not be an active generation if there has been a break
* but no subsequent reset. * but no subsequent reset.
...@@ -229,7 +230,7 @@ public class CyclicBarrier { ...@@ -229,7 +230,7 @@ public class CyclicBarrier {
} }
/** /**
* Creates a new <tt>CyclicBarrier</tt> that will trip when the * Creates a new {@code CyclicBarrier} that will trip when the
* given number of parties (threads) are waiting upon it, and which * given number of parties (threads) are waiting upon it, and which
* will execute the given barrier action when the barrier is tripped, * will execute the given barrier action when the barrier is tripped,
* performed by the last thread entering the barrier. * performed by the last thread entering the barrier.
...@@ -248,7 +249,7 @@ public class CyclicBarrier { ...@@ -248,7 +249,7 @@ public class CyclicBarrier {
} }
/** /**
* Creates a new <tt>CyclicBarrier</tt> that will trip when the * Creates a new {@code CyclicBarrier} that will trip when the
* given number of parties (threads) are waiting upon it, and * given number of parties (threads) are waiting upon it, and
* does not perform a predefined action when the barrier is tripped. * does not perform a predefined action when the barrier is tripped.
* *
...@@ -271,7 +272,7 @@ public class CyclicBarrier { ...@@ -271,7 +272,7 @@ public class CyclicBarrier {
/** /**
* Waits until all {@linkplain #getParties parties} have invoked * Waits until all {@linkplain #getParties parties} have invoked
* <tt>await</tt> on this barrier. * {@code await} on this barrier.
* *
* <p>If the current thread is not the last to arrive then it is * <p>If the current thread is not the last to arrive then it is
* disabled for thread scheduling purposes and lies dormant until * disabled for thread scheduling purposes and lies dormant until
...@@ -296,7 +297,7 @@ public class CyclicBarrier { ...@@ -296,7 +297,7 @@ public class CyclicBarrier {
* *
* <p>If the barrier is {@link #reset} while any thread is waiting, * <p>If the barrier is {@link #reset} while any thread is waiting,
* or if the barrier {@linkplain #isBroken is broken} when * or if the barrier {@linkplain #isBroken is broken} when
* <tt>await</tt> is invoked, or while any thread is waiting, then * {@code await} is invoked, or while any thread is waiting, then
* {@link BrokenBarrierException} is thrown. * {@link BrokenBarrierException} is thrown.
* *
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting, * <p>If any thread is {@linkplain Thread#interrupt interrupted} while waiting,
...@@ -313,7 +314,7 @@ public class CyclicBarrier { ...@@ -313,7 +314,7 @@ public class CyclicBarrier {
* the broken state. * the broken state.
* *
* @return the arrival index of the current thread, where index * @return the arrival index of the current thread, where index
* <tt>{@link #getParties()} - 1</tt> indicates the first * {@code getParties() - 1} indicates the first
* to arrive and zero indicates the last to arrive * to arrive and zero indicates the last to arrive
* @throws InterruptedException if the current thread was interrupted * @throws InterruptedException if the current thread was interrupted
* while waiting * while waiting
...@@ -321,7 +322,7 @@ public class CyclicBarrier { ...@@ -321,7 +322,7 @@ public class CyclicBarrier {
* interrupted or timed out while the current thread was * interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was * waiting, or the barrier was reset, or the barrier was
* broken when {@code await} was called, or the barrier * broken when {@code await} was called, or the barrier
* action (if present) failed due an exception. * action (if present) failed due to an exception
*/ */
public int await() throws InterruptedException, BrokenBarrierException { public int await() throws InterruptedException, BrokenBarrierException {
try { try {
...@@ -333,7 +334,7 @@ public class CyclicBarrier { ...@@ -333,7 +334,7 @@ public class CyclicBarrier {
/** /**
* Waits until all {@linkplain #getParties parties} have invoked * Waits until all {@linkplain #getParties parties} have invoked
* <tt>await</tt> on this barrier, or the specified waiting time elapses. * {@code await} on this barrier, or the specified waiting time elapses.
* *
* <p>If the current thread is not the last to arrive then it is * <p>If the current thread is not the last to arrive then it is
* disabled for thread scheduling purposes and lies dormant until * disabled for thread scheduling purposes and lies dormant until
...@@ -363,7 +364,7 @@ public class CyclicBarrier { ...@@ -363,7 +364,7 @@ public class CyclicBarrier {
* *
* <p>If the barrier is {@link #reset} while any thread is waiting, * <p>If the barrier is {@link #reset} while any thread is waiting,
* or if the barrier {@linkplain #isBroken is broken} when * or if the barrier {@linkplain #isBroken is broken} when
* <tt>await</tt> is invoked, or while any thread is waiting, then * {@code await} is invoked, or while any thread is waiting, then
* {@link BrokenBarrierException} is thrown. * {@link BrokenBarrierException} is thrown.
* *
* <p>If any thread is {@linkplain Thread#interrupt interrupted} while * <p>If any thread is {@linkplain Thread#interrupt interrupted} while
...@@ -382,7 +383,7 @@ public class CyclicBarrier { ...@@ -382,7 +383,7 @@ public class CyclicBarrier {
* @param timeout the time to wait for the barrier * @param timeout the time to wait for the barrier
* @param unit the time unit of the timeout parameter * @param unit the time unit of the timeout parameter
* @return the arrival index of the current thread, where index * @return the arrival index of the current thread, where index
* <tt>{@link #getParties()} - 1</tt> indicates the first * {@code getParties() - 1} indicates the first
* to arrive and zero indicates the last to arrive * to arrive and zero indicates the last to arrive
* @throws InterruptedException if the current thread was interrupted * @throws InterruptedException if the current thread was interrupted
* while waiting * while waiting
...@@ -391,7 +392,7 @@ public class CyclicBarrier { ...@@ -391,7 +392,7 @@ public class CyclicBarrier {
* interrupted or timed out while the current thread was * interrupted or timed out while the current thread was
* waiting, or the barrier was reset, or the barrier was broken * waiting, or the barrier was reset, or the barrier was broken
* when {@code await} was called, or the barrier action (if * when {@code await} was called, or the barrier action (if
* present) failed due an exception * present) failed due to an exception
*/ */
public int await(long timeout, TimeUnit unit) public int await(long timeout, TimeUnit unit)
throws InterruptedException, throws InterruptedException,
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
package java.util.concurrent; package java.util.concurrent;
import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
...@@ -17,15 +16,15 @@ import java.util.*; ...@@ -17,15 +16,15 @@ import java.util.*;
/** /**
* An unbounded {@linkplain BlockingQueue blocking queue} of * An unbounded {@linkplain BlockingQueue blocking queue} of
* <tt>Delayed</tt> elements, in which an element can only be taken * {@code Delayed} elements, in which an element can only be taken
* when its delay has expired. The <em>head</em> of the queue is that * when its delay has expired. The <em>head</em> of the queue is that
* <tt>Delayed</tt> element whose delay expired furthest in the * {@code Delayed} element whose delay expired furthest in the
* past. If no delay has expired there is no head and <tt>poll</tt> * past. If no delay has expired there is no head and {@code poll}
* will return <tt>null</tt>. Expiration occurs when an element's * will return {@code null}. Expiration occurs when an element's
* <tt>getDelay(TimeUnit.NANOSECONDS)</tt> method returns a value less * {@code getDelay(TimeUnit.NANOSECONDS)} method returns a value less
* than or equal to zero. Even though unexpired elements cannot be * than or equal to zero. Even though unexpired elements cannot be
* removed using <tt>take</tt> or <tt>poll</tt>, they are otherwise * removed using {@code take} or {@code poll}, they are otherwise
* treated as normal elements. For example, the <tt>size</tt> method * treated as normal elements. For example, the {@code size} method
* returns the count of both expired and unexpired elements. * returns the count of both expired and unexpired elements.
* This queue does not permit null elements. * This queue does not permit null elements.
* *
...@@ -39,11 +38,10 @@ import java.util.*; ...@@ -39,11 +38,10 @@ import java.util.*;
* @author Doug Lea * @author Doug Lea
* @param <E> the type of elements held in this collection * @param <E> the type of elements held in this collection
*/ */
public class DelayQueue<E extends Delayed> extends AbstractQueue<E> public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
implements BlockingQueue<E> { implements BlockingQueue<E> {
private transient final ReentrantLock lock = new ReentrantLock(); private final transient ReentrantLock lock = new ReentrantLock();
private final PriorityQueue<E> q = new PriorityQueue<E>(); private final PriorityQueue<E> q = new PriorityQueue<E>();
/** /**
...@@ -72,12 +70,12 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -72,12 +70,12 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
private final Condition available = lock.newCondition(); private final Condition available = lock.newCondition();
/** /**
* Creates a new <tt>DelayQueue</tt> that is initially empty. * Creates a new {@code DelayQueue} that is initially empty.
*/ */
public DelayQueue() {} public DelayQueue() {}
/** /**
* Creates a <tt>DelayQueue</tt> initially containing the elements of the * Creates a {@code DelayQueue} initially containing the elements of the
* given collection of {@link Delayed} instances. * given collection of {@link Delayed} instances.
* *
* @param c the collection of elements to initially contain * @param c the collection of elements to initially contain
...@@ -92,7 +90,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -92,7 +90,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* Inserts the specified element into this delay queue. * Inserts the specified element into this delay queue.
* *
* @param e the element to add * @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 NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
public boolean add(E e) { public boolean add(E e) {
...@@ -103,7 +101,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -103,7 +101,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* Inserts the specified element into this delay queue. * Inserts the specified element into this delay queue.
* *
* @param e the element to add * @param e the element to add
* @return <tt>true</tt> * @return {@code true}
* @throws NullPointerException if the specified element is null * @throws NullPointerException if the specified element is null
*/ */
public boolean offer(E e) { public boolean offer(E e) {
...@@ -139,7 +137,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -139,7 +137,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* @param e the element to add * @param e the element to add
* @param timeout This parameter is ignored as the method never blocks * @param timeout This parameter is ignored as the method never blocks
* @param unit This parameter is ignored as the method never blocks * @param unit This parameter is ignored as the method never blocks
* @return <tt>true</tt> * @return {@code true}
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
public boolean offer(E e, long timeout, TimeUnit unit) { public boolean offer(E e, long timeout, TimeUnit unit) {
...@@ -147,10 +145,10 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -147,10 +145,10 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
} }
/** /**
* Retrieves and removes the head of this queue, or returns <tt>null</tt> * Retrieves and removes the head of this queue, or returns {@code null}
* if this queue has no elements with an expired delay. * if this queue has no elements with an expired delay.
* *
* @return the head of this queue, or <tt>null</tt> if this * @return the head of this queue, or {@code null} if this
* queue has no elements with an expired delay * queue has no elements with an expired delay
*/ */
public E poll() { public E poll() {
...@@ -186,7 +184,8 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -186,7 +184,8 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
long delay = first.getDelay(NANOSECONDS); long delay = first.getDelay(NANOSECONDS);
if (delay <= 0) if (delay <= 0)
return q.poll(); return q.poll();
else if (leader != null) first = null; // don't retain ref while waiting
if (leader != null)
available.await(); available.await();
else { else {
Thread thisThread = Thread.currentThread(); Thread thisThread = Thread.currentThread();
...@@ -212,7 +211,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -212,7 +211,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* until an element with an expired delay is available on this queue, * until an element with an expired delay is available on this queue,
* or the specified wait time expires. * or the specified wait time expires.
* *
* @return the head of this queue, or <tt>null</tt> if the * @return the head of this queue, or {@code null} if the
* specified waiting time elapses before an element with * specified waiting time elapses before an element with
* an expired delay becomes available * an expired delay becomes available
* @throws InterruptedException {@inheritDoc} * @throws InterruptedException {@inheritDoc}
...@@ -235,6 +234,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -235,6 +234,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
return q.poll(); return q.poll();
if (nanos <= 0) if (nanos <= 0)
return null; return null;
first = null; // don't retain ref while waiting
if (nanos < delay || leader != null) if (nanos < delay || leader != null)
nanos = available.awaitNanos(nanos); nanos = available.awaitNanos(nanos);
else { else {
...@@ -259,13 +259,13 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -259,13 +259,13 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
/** /**
* Retrieves, but does not remove, the head of this queue, or * Retrieves, but does not remove, the head of this queue, or
* returns <tt>null</tt> if this queue is empty. Unlike * returns {@code null} if this queue is empty. Unlike
* <tt>poll</tt>, if no expired elements are available in the queue, * {@code poll}, if no expired elements are available in the queue,
* this method returns the element that will expire next, * this method returns the element that will expire next,
* if one exists. * if one exists.
* *
* @return the head of this queue, or <tt>null</tt> if this * @return the head of this queue, or {@code null} if this
* queue is empty. * queue is empty
*/ */
public E peek() { public E peek() {
final ReentrantLock lock = this.lock; final ReentrantLock lock = this.lock;
...@@ -288,7 +288,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -288,7 +288,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
} }
/** /**
* Return first element only if it is expired. * Returns first element only if it is expired.
* Used only by drainTo. Call only when holding lock. * Used only by drainTo. Call only when holding lock.
*/ */
private E peekExpired() { private E peekExpired() {
...@@ -369,10 +369,10 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -369,10 +369,10 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
} }
/** /**
* Always returns <tt>Integer.MAX_VALUE</tt> because * Always returns {@code Integer.MAX_VALUE} because
* a <tt>DelayQueue</tt> is not capacity constrained. * a {@code DelayQueue} is not capacity constrained.
* *
* @return <tt>Integer.MAX_VALUE</tt> * @return {@code Integer.MAX_VALUE}
*/ */
public int remainingCapacity() { public int remainingCapacity() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
...@@ -412,7 +412,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -412,7 +412,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* <p>If this queue fits in the specified array with room to spare * <p>If this queue fits in the specified array with room to spare
* (i.e., the array has more elements than this queue), the element in * (i.e., the array has more elements than this queue), the element in
* the array immediately following the end of the queue is set to * the array immediately following the end of the queue is set to
* <tt>null</tt>. * {@code null}.
* *
* <p>Like the {@link #toArray()} method, this method acts as bridge between * <p>Like the {@link #toArray()} method, this method acts as bridge between
* array-based and collection-based APIs. Further, this method allows * array-based and collection-based APIs. Further, this method allows
...@@ -420,12 +420,12 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -420,12 +420,12 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* under certain circumstances, be used to save allocation costs. * under certain circumstances, be used to save allocation costs.
* *
* <p>The following code can be used to dump a delay queue into a newly * <p>The following code can be used to dump a delay queue into a newly
* allocated array of <tt>Delayed</tt>: * allocated array of {@code Delayed}:
* *
* <pre> {@code Delayed[] a = q.toArray(new Delayed[0]);}</pre> * <pre> {@code Delayed[] a = q.toArray(new Delayed[0]);}</pre>
* *
* Note that <tt>toArray(new Object[0])</tt> is identical in function to * Note that {@code toArray(new Object[0])} is identical in function to
* <tt>toArray()</tt>. * {@code toArray()}.
* *
* @param a the array into which the elements of the queue are to * @param a the array into which the elements of the queue are to
* be stored, if it is big enough; otherwise, a new array of the * be stored, if it is big enough; otherwise, a new array of the
......
...@@ -11,8 +11,8 @@ package java.util.concurrent; ...@@ -11,8 +11,8 @@ package java.util.concurrent;
* acted upon after a given delay. * acted upon after a given delay.
* *
* <p>An implementation of this interface must define a * <p>An implementation of this interface must define a
* <tt>compareTo</tt> method that provides an ordering consistent with * {@code compareTo} method that provides an ordering consistent with
* its <tt>getDelay</tt> method. * its {@code getDelay} method.
* *
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment