From ff24088c866864fa670bbfdd068b1a50b6bcf0db Mon Sep 17 00:00:00 2001
From: Doug Lea
Date: Thu, 26 Jun 2025 12:04:42 +0000
Subject: [PATCH] =?UTF-8?q?8359919:=20Minor=20java.util.concurrent=20doc?=
=?UTF-8?q?=20improvements=208187775:=20AtomicReferenceFieldUpdater=20does?=
=?UTF-8?q?=20not=20support=20static=20fields=208254060:=20SubmissionPubli?=
=?UTF-8?q?sher=20close=20hangs=20if=20a=20publication=20is=20pending=2082?=
=?UTF-8?q?10149:=20Example=20in=20JavaDoc=20for=20java.util.concurrent.Fl?=
=?UTF-8?q?ow=20violates=20Reactive=20Streams=20spec=208199501:=20Improve?=
=?UTF-8?q?=20documentation=20of=20CompletableFuture,=20CompletionStage=20?=
=?UTF-8?q?8233050:=20CompletableFuture=20`whenComplete`=20and=20`thenAppl?=
=?UTF-8?q?y`=20change=20exceptional=20result=208210312:=20JavaDoc=20examp?=
=?UTF-8?q?le=20in=20SubmissionPublisher=20will=20potentially=20crash=2082?=
=?UTF-8?q?92365:=20CompletableFuture=20and=20CompletionStage=20should=20d?=
=?UTF-8?q?ocument=20Memory=20Model=20guarantees=208356304:=20Define=20"en?=
=?UTF-8?q?abled"=20in=20ScheduledExecutorService=208353155:=20FutureTask#?=
=?UTF-8?q?run():=20doc=20implies=20synchronous,=20implementation=20is=20a?=
=?UTF-8?q?sync=208186959:=20Clarify=20that=20Executors.newScheduledThread?=
=?UTF-8?q?Pool()=20is=20fixed-size=208190889:=20TimeUnit.wait=20should=20?=
=?UTF-8?q?document=20IllegalMonitorStateException=206351533:=20CyclicBarr?=
=?UTF-8?q?ier=20reset()=20should=20return=20the=20number=20of=20awaiters?=
=?UTF-8?q?=206317534:=20CyclicBarrier=20should=20have=20a=20cancel()=20me?=
=?UTF-8?q?thod=208195628:=20Documentation=20for=20lock(),=20trylock(),=20?=
=?UTF-8?q?lockInterruptibly=E2=80=8B()=20=20of=20ReentrantReadWriteLock.W?=
=?UTF-8?q?riteLock=20needs=20to=20be=20corrected=208333172:=20Document=20?=
=?UTF-8?q?a=20recommendation=20to=20use=20VarHandles=20instead=20of=20jav?=
=?UTF-8?q?a.util.concurrent.atomic.*FieldUpdater=206374942:=20Improve=20t?=
=?UTF-8?q?hread=20safety=20of=20collection=20.equals()=20methods=20717695?=
=?UTF-8?q?7:=20ExecutorService=20submit=20method=20javaDoc=20enhancement?=
=?UTF-8?q?=208172177:=20Improve=20documentation=20for=20CompletionExcepti?=
=?UTF-8?q?on=20handling=206714849:=20ReentrantReadWriteLock:=20Abnormal?=
=?UTF-8?q?=20behavior=20in=20non-fair=20mode=206625724:=20Allow=20Reentra?=
=?UTF-8?q?ntReadWriteLock=20to=20not=20track=20per-thread=20read=20holds?=
=?UTF-8?q?=206526284:=20Improve=20AbstractExecutorService=20javadoc=20813?=
=?UTF-8?q?7156:=20Javadoc=20for=20Future=20is=20misleading=20with=20respe?=
=?UTF-8?q?ct=20to=20cancellation=206663476:=20FutureTask.get()=20may=20re?=
=?UTF-8?q?turn=20null=20if=20set()=20is=20not=20called=20from=20run()=208?=
=?UTF-8?q?311131:=20ConcurrentHashMap.forEachKey=20parallelismThreshold?=
=?UTF-8?q?=20description=20could=20be=20clearer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reviewed-by: alanb
---
.../concurrent/AbstractExecutorService.java | 20 +-
.../java/util/concurrent/CompletionStage.java | 268 +++++++++---------
.../util/concurrent/ConcurrentHashMap.java | 64 ++---
.../java/util/concurrent/CyclicBarrier.java | 5 +-
.../java/util/concurrent/ExecutorService.java | 4 +-
.../java/util/concurrent/Executors.java | 4 +-
.../classes/java/util/concurrent/Flow.java | 3 +-
.../java/util/concurrent/ForkJoinPool.java | 12 +-
.../classes/java/util/concurrent/Future.java | 20 ++
.../java/util/concurrent/FutureTask.java | 4 +-
.../java/util/concurrent/RunnableFuture.java | 5 +-
.../concurrent/ScheduledExecutorService.java | 18 +-
.../ScheduledThreadPoolExecutor.java | 6 +-
.../util/concurrent/SubmissionPublisher.java | 10 +-
.../java/util/concurrent/TimeUnit.java | 2 +
.../atomic/AtomicIntegerFieldUpdater.java | 9 +-
.../atomic/AtomicLongFieldUpdater.java | 9 +-
.../atomic/AtomicReferenceFieldUpdater.java | 31 +-
.../locks/ReentrantReadWriteLock.java | 28 +-
.../java/util/concurrent/package-info.java | 4 +-
20 files changed, 304 insertions(+), 222 deletions(-)
diff --git a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
index 0d26607591d..c249f630163 100644
--- a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
+++ b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
@@ -44,16 +44,16 @@ import java.util.List;
import java.util.Objects;
/**
- * Provides default implementations of {@link ExecutorService}
- * execution methods. This class implements the {@code submit},
- * {@code invokeAny} and {@code invokeAll} methods using a
- * {@link RunnableFuture} returned by {@code newTaskFor}, which defaults
- * to the {@link FutureTask} class provided in this package. For example,
- * the implementation of {@code submit(Runnable)} creates an
- * associated {@code RunnableFuture} that is executed and
- * returned. Subclasses may override the {@code newTaskFor} methods
- * to return {@code RunnableFuture} implementations other than
- * {@code FutureTask}.
+ * Provides default implementations of {@link ExecutorService} methods
+ * other than {@link Executor#execute}. This class implements the {@code
+ * submit}, {@code invokeAny} and {@code invokeAll} methods using a
+ * {@link RunnableFuture} returned by {@code newTaskFor}, which
+ * defaults to the {@link FutureTask} class provided in this package.
+ * For example, the implementation of {@code submit(Runnable)} creates
+ * an associated {@code RunnableFuture} that is executed and
+ * returned. Subclasses may override the {@code newTaskFor} methods to
+ * return {@code RunnableFuture} implementations other than {@code
+ * FutureTask}.
*
* Extension example. Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use
diff --git a/src/java.base/share/classes/java/util/concurrent/CompletionStage.java b/src/java.base/share/classes/java/util/concurrent/CompletionStage.java
index 6ff31c61049..b4368842865 100644
--- a/src/java.base/share/classes/java/util/concurrent/CompletionStage.java
+++ b/src/java.base/share/classes/java/util/concurrent/CompletionStage.java
@@ -43,7 +43,7 @@ import java.util.function.Function;
/**
* A stage of a possibly asynchronous computation, that performs an
* action or computes a value when another CompletionStage completes.
- * A stage completes upon termination of its computation, but this may
+ * A stage completes upon termination of its computation, which may
* in turn trigger other dependent stages. The functionality defined
* in this interface takes only a few basic forms, which expand out to
* a larger set of methods to capture a range of usage styles:
@@ -97,18 +97,25 @@ import java.util.function.Function;
* In all other cases, if a stage's computation terminates abruptly
* with an (unchecked) exception or error, then all dependent stages
* requiring its completion complete exceptionally as well, with a
- * {@link CompletionException} holding the exception as its cause. If
- * a stage is dependent on both of two stages, and both
- * complete exceptionally, then the CompletionException may correspond
- * to either one of these exceptions. If a stage is dependent on
- * either of two others, and only one of them completes
- * exceptionally, no guarantees are made about whether the dependent
- * stage completes normally or exceptionally. In the case of method
- * {@code whenComplete}, when the supplied action itself encounters an
- * exception, then the stage completes exceptionally with this
- * exception unless the source stage also completed exceptionally, in
- * which case the exceptional completion from the source stage is
- * given preference and propagated to the dependent stage.
+ * {@link CompletionException} holding the exception as its
+ * cause. This convention distinguishes exceptions in an action itself
+ * from those it depends on. If they are to be handled in the same
+ * way, instead catch {@link RuntimeException} (possibly inspecting
+ * the exception's {@code getCause()}). If a stage is dependent on
+ * both of two stages, and both complete exceptionally, then
+ * the CompletionException may correspond to either one of these
+ * exceptions. If a stage is dependent on either of two
+ * others, and only one of them completes exceptionally, no guarantees
+ * are made about whether the dependent stage completes normally or
+ * exceptionally. In the case of method {@code whenComplete}, when the
+ * supplied action itself encounters an exception, then the stage
+ * completes exceptionally with that exception unless the source stage
+ * also completed exceptionally, in which case the exceptional
+ * completion from the source stage is given preference and propagated
+ * to the dependent stage. Applications are encouraged to maintain
+ * these conventions, avoiding unnecessary nesting when rethrowing, as
+ * in {@code throw (ex instanceof CompletionException) ? ex : new
+ * CompletionException(ex)}.
*
*
*
@@ -137,7 +144,7 @@ import java.util.function.Function;
* }
* }}
*
- *
This interface does not define methods for initially creating,
+ *
The {@code CompletionStage} interface does not define methods for initially creating,
* forcibly completing normally or exceptionally, probing completion
* status or results, or awaiting completion of a stage.
* Implementations of CompletionStage may provide means of achieving
@@ -145,6 +152,13 @@ import java.util.function.Function;
* enables interoperability among different implementations of this
* interface by providing a common conversion type.
*
+ *
Memory consistency effects: Actions in a thread prior to the
+ * submission of a computation producing a {@code CompletionStage} happen-before
+ * that computation begins. And actions taken by {@code
+ * CompletionStage x} happen-before actions of any dependent
+ * stage subsequent to {@code x}'s completion.
+ *
* @param the type of values the stage produces or consumes
*
* @author Doug Lea
@@ -153,8 +167,8 @@ import java.util.function.Function;
public interface CompletionStage {
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed with this stage's result as the argument
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed with {@code this} stage's result as the argument
* to the supplied function.
*
* This method is analogous to
@@ -172,9 +186,9 @@ public interface CompletionStage {
public CompletionStage thenApply(Function super T,? extends U> fn);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed using this stage's default asynchronous
- * execution facility, with this stage's result as the argument to
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed using {@code this} stage's default asynchronous
+ * execution facility, with {@code this} stage's result as the argument to
* the supplied function.
*
* See the {@link CompletionStage} documentation for rules
@@ -189,8 +203,8 @@ public interface CompletionStage {
(Function super T,? extends U> fn);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed using the supplied Executor, with this
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed using the supplied Executor, with {@code this}
* stage's result as the argument to the supplied function.
*
* See the {@link CompletionStage} documentation for rules
@@ -207,8 +221,8 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed with this stage's result as the argument
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed with {@code this} stage's result as the argument
* to the supplied action.
*
* See the {@link CompletionStage} documentation for rules
@@ -221,9 +235,9 @@ public interface CompletionStage {
public CompletionStage thenAccept(Consumer super T> action);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed using this stage's default asynchronous
- * execution facility, with this stage's result as the argument to
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed using {@code this} stage's default asynchronous
+ * execution facility, with {@code this} stage's result as the argument to
* the supplied action.
*
* See the {@link CompletionStage} documentation for rules
@@ -236,8 +250,8 @@ public interface CompletionStage {
public CompletionStage thenAcceptAsync(Consumer super T> action);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed using the supplied Executor, with this
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, is executed using the supplied Executor, with {@code this}
* stage's result as the argument to the supplied action.
*
* See the {@link CompletionStage} documentation for rules
@@ -251,7 +265,7 @@ public interface CompletionStage {
public CompletionStage thenAcceptAsync(Consumer super T> action,
Executor executor);
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* normally, executes the given action.
*
* See the {@link CompletionStage} documentation for rules
@@ -264,8 +278,8 @@ public interface CompletionStage {
public CompletionStage thenRun(Runnable action);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, executes the given action using this stage's default
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * normally, executes the given action using {@code this} stage's default
* asynchronous execution facility.
*
* See the {@link CompletionStage} documentation for rules
@@ -278,7 +292,7 @@ public interface CompletionStage {
public CompletionStage thenRunAsync(Runnable action);
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* normally, executes the given action using the supplied Executor.
*
* See the {@link CompletionStage} documentation for rules
@@ -293,7 +307,7 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, is executed with the two
* results as arguments to the supplied function.
*
@@ -312,8 +326,8 @@ public interface CompletionStage {
BiFunction super T,? super U,? extends V> fn);
/**
- * Returns a new CompletionStage that, when this and the other
- * given stage both complete normally, is executed using this
+ * Returns a new CompletionStage that, when {@code this} and the other
+ * given stage both complete normally, is executed using {@code this}
* stage's default asynchronous execution facility, with the two
* results as arguments to the supplied function.
*
@@ -332,7 +346,7 @@ public interface CompletionStage {
BiFunction super T,? super U,? extends V> fn);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, is executed using the
* supplied executor, with the two results as arguments to the
* supplied function.
@@ -354,7 +368,7 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, is executed with the two
* results as arguments to the supplied action.
*
@@ -372,8 +386,8 @@ public interface CompletionStage {
BiConsumer super T, ? super U> action);
/**
- * Returns a new CompletionStage that, when this and the other
- * given stage both complete normally, is executed using this
+ * Returns a new CompletionStage that, when {@code this} and the other
+ * given stage both complete normally, is executed using {@code this}
* stage's default asynchronous execution facility, with the two
* results as arguments to the supplied action.
*
@@ -391,7 +405,7 @@ public interface CompletionStage {
BiConsumer super T, ? super U> action);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, is executed using the
* supplied executor, with the two results as arguments to the
* supplied action.
@@ -412,7 +426,7 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, executes the given action.
*
* See the {@link CompletionStage} documentation for rules
@@ -426,9 +440,9 @@ public interface CompletionStage {
public CompletionStage runAfterBoth(CompletionStage> other,
Runnable action);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, executes the given action
- * using this stage's default asynchronous execution facility.
+ * using {@code this} stage's default asynchronous execution facility.
*
* See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
@@ -442,7 +456,7 @@ public interface CompletionStage {
Runnable action);
/**
- * Returns a new CompletionStage that, when this and the other
+ * Returns a new CompletionStage that, when {@code this} and the other
* given stage both complete normally, executes the given action
* using the supplied executor.
*
@@ -459,7 +473,7 @@ public interface CompletionStage {
Runnable action,
Executor executor);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, is executed with the
* corresponding result as argument to the supplied function.
*
@@ -477,8 +491,8 @@ public interface CompletionStage {
Function super T, U> fn);
/**
- * Returns a new CompletionStage that, when either this or the
- * other given stage complete normally, is executed using this
+ * Returns a new CompletionStage that, when either {@code this} or the
+ * other given stage complete normally, is executed using {@code this}
* stage's default asynchronous execution facility, with the
* corresponding result as argument to the supplied function.
*
@@ -496,7 +510,7 @@ public interface CompletionStage {
Function super T, U> fn);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, is executed using the
* supplied executor, with the corresponding result as argument to
* the supplied function.
@@ -517,7 +531,7 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, is executed with the
* corresponding result as argument to the supplied action.
*
@@ -534,8 +548,8 @@ public interface CompletionStage {
Consumer super T> action);
/**
- * Returns a new CompletionStage that, when either this or the
- * other given stage complete normally, is executed using this
+ * Returns a new CompletionStage that, when either {@code this} or the
+ * other given stage complete normally, is executed using {@code this}
* stage's default asynchronous execution facility, with the
* corresponding result as argument to the supplied action.
*
@@ -552,7 +566,7 @@ public interface CompletionStage {
Consumer super T> action);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, is executed using the
* supplied executor, with the corresponding result as argument to
* the supplied action.
@@ -572,7 +586,7 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, executes the given action.
*
* See the {@link CompletionStage} documentation for rules
@@ -587,9 +601,9 @@ public interface CompletionStage {
Runnable action);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, executes the given action
- * using this stage's default asynchronous execution facility.
+ * using {@code this} stage's default asynchronous execution facility.
*
* See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
@@ -604,7 +618,7 @@ public interface CompletionStage {
Runnable action);
/**
- * Returns a new CompletionStage that, when either this or the
+ * Returns a new CompletionStage that, when either {@code this} or the
* other given stage complete normally, executes the given action
* using the supplied executor.
*
@@ -626,10 +640,10 @@ public interface CompletionStage {
* Returns a new CompletionStage that is completed with the same
* value as the CompletionStage returned by the given function.
*
- * When this stage completes normally, the given function is
- * invoked with this stage's result as the argument, returning
+ *
When {@code this} stage completes normally, the given function is
+ * invoked with {@code this} stage's result as the argument, returning
* another CompletionStage. When that stage completes normally,
- * the CompletionStage returned by this method is completed with
+ * the CompletionStage returned is completed with
* the same value.
*
*
To ensure progress, the supplied function must arrange
@@ -652,13 +666,13 @@ public interface CompletionStage {
/**
* Returns a new CompletionStage that is completed with the same
* value as the CompletionStage returned by the given function,
- * executed using this stage's default asynchronous execution
+ * executed using {@code this} stage's default asynchronous execution
* facility.
*
- * When this stage completes normally, the given function is
- * invoked with this stage's result as the argument, returning
+ *
When {@code this} stage completes normally, the given function is
+ * invoked with {@code this} stage's result as the argument, returning
* another CompletionStage. When that stage completes normally,
- * the CompletionStage returned by this method is completed with
+ * the CompletionStage returned is completed with
* the same value.
*
*
To ensure progress, the supplied function must arrange
@@ -679,10 +693,10 @@ public interface CompletionStage {
* value as the CompletionStage returned by the given function,
* executed using the supplied Executor.
*
- * When this stage completes normally, the given function is
- * invoked with this stage's result as the argument, returning
+ *
When {@code this} stage completes normally, the given function is
+ * invoked with {@code this} stage's result as the argument, returning
* another CompletionStage. When that stage completes normally,
- * the CompletionStage returned by this method is completed with
+ * the CompletionStage returned by {@code this} method is completed with
* the same value.
*
*
To ensure progress, the supplied function must arrange
@@ -701,13 +715,13 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this stage completes
- * either normally or exceptionally, is executed with this stage's
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * either normally or exceptionally, is executed with {@code this} stage's
* result and exception as arguments to the supplied function.
*
- * When this stage is complete, the given function is invoked
+ *
When {@code this} stage is complete, the given function is invoked
* with the result (or {@code null} if none) and the exception (or
- * {@code null} if none) of this stage as arguments, and the
+ * {@code null} if none) of {@code this} stage as arguments, and the
* function's result is used to complete the returned stage.
*
* @param fn the function to use to compute the value of the
@@ -719,14 +733,14 @@ public interface CompletionStage {
(BiFunction super T, Throwable, ? extends U> fn);
/**
- * Returns a new CompletionStage that, when this stage completes
- * either normally or exceptionally, is executed using this stage's
- * default asynchronous execution facility, with this stage's
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * either normally or exceptionally, is executed using {@code this} stage's
+ * default asynchronous execution facility, with {@code this} stage's
* result and exception as arguments to the supplied function.
*
- * When this stage is complete, the given function is invoked
+ *
When {@code this} stage is complete, the given function is invoked
* with the result (or {@code null} if none) and the exception (or
- * {@code null} if none) of this stage as arguments, and the
+ * {@code null} if none) of {@code this} stage as arguments, and the
* function's result is used to complete the returned stage.
*
* @param fn the function to use to compute the value of the
@@ -738,14 +752,14 @@ public interface CompletionStage {
(BiFunction super T, Throwable, ? extends U> fn);
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* either normally or exceptionally, is executed using the
- * supplied executor, with this stage's result and exception as
+ * supplied executor, with {@code this} stage's result and exception as
* arguments to the supplied function.
*
- * When this stage is complete, the given function is invoked
+ *
When {@code this} stage is complete, the given function is invoked
* with the result (or {@code null} if none) and the exception (or
- * {@code null} if none) of this stage as arguments, and the
+ * {@code null} if none) of {@code this} stage as arguments, and the
* function's result is used to complete the returned stage.
*
* @param fn the function to use to compute the value of the
@@ -760,22 +774,22 @@ public interface CompletionStage {
/**
* Returns a new CompletionStage with the same result or exception as
- * this stage, that executes the given action when this stage completes.
+ * {@code this} stage, that executes the given action when {@code this} stage completes.
*
- * When this stage is complete, the given action is invoked
+ *
When {@code this} stage is complete, the given action is invoked
* with the result (or {@code null} if none) and the exception (or
- * {@code null} if none) of this stage as arguments. The returned
+ * {@code null} if none) of {@code this} stage as arguments. The returned
* stage is completed when the action returns.
*
*
Unlike method {@link #handle handle},
- * this method is not designed to translate completion outcomes,
+ * method {@code whenComplete} is not designed to translate completion outcomes,
* so the supplied action should not throw an exception. However,
- * if it does, the following rules apply: if this stage completed
+ * if it does, the following rules apply: if {@code this} stage completed
* normally but the supplied action throws an exception, then the
* returned stage completes exceptionally with the supplied
- * action's exception. Or, if this stage completed exceptionally
+ * action's exception. Or, if {@code this} stage completed exceptionally
* and the supplied action throws an exception, then the returned
- * stage completes exceptionally with this stage's exception.
+ * stage completes exceptionally with {@code this} stage's exception.
*
* @param action the action to perform
* @return the new CompletionStage
@@ -785,23 +799,23 @@ public interface CompletionStage {
/**
* Returns a new CompletionStage with the same result or exception as
- * this stage, that executes the given action using this stage's
- * default asynchronous execution facility when this stage completes.
+ * {@code this} stage, that executes the given action using {@code this} stage's
+ * default asynchronous execution facility when {@code this} stage completes.
*
- * When this stage is complete, the given action is invoked with the
+ *
When {@code this} stage is complete, the given action is invoked with the
* result (or {@code null} if none) and the exception (or {@code null}
- * if none) of this stage as arguments. The returned stage is completed
+ * if none) of {@code this} stage as arguments. The returned stage is completed
* when the action returns.
*
*
Unlike method {@link #handleAsync(BiFunction) handleAsync},
- * this method is not designed to translate completion outcomes,
+ * method {@code whenCompleteAsync} is not designed to translate completion outcomes,
* so the supplied action should not throw an exception. However,
- * if it does, the following rules apply: If this stage completed
+ * if it does, the following rules apply: If {@code this} stage completed
* normally but the supplied action throws an exception, then the
* returned stage completes exceptionally with the supplied
- * action's exception. Or, if this stage completed exceptionally
+ * action's exception. Or, if {@code this} stage completed exceptionally
* and the supplied action throws an exception, then the returned
- * stage completes exceptionally with this stage's exception.
+ * stage completes exceptionally with {@code this} stage's exception.
*
* @param action the action to perform
* @return the new CompletionStage
@@ -811,23 +825,23 @@ public interface CompletionStage {
/**
* Returns a new CompletionStage with the same result or exception as
- * this stage, that executes the given action using the supplied
- * Executor when this stage completes.
+ * {@code this} stage, that executes the given action using the supplied
+ * Executor when {@code this} stage completes.
*
- * When this stage is complete, the given action is invoked with the
+ *
When {@code this} stage is complete, the given action is invoked with the
* result (or {@code null} if none) and the exception (or {@code null}
- * if none) of this stage as arguments. The returned stage is completed
+ * if none) of {@code this} stage as arguments. The returned stage is completed
* when the action returns.
*
*
Unlike method {@link #handleAsync(BiFunction,Executor) handleAsync},
- * this method is not designed to translate completion outcomes,
+ * method {@code whenCompleteAsync} is not designed to translate completion outcomes,
* so the supplied action should not throw an exception. However,
- * if it does, the following rules apply: If this stage completed
+ * if it does, the following rules apply: If {@code this} stage completed
* normally but the supplied action throws an exception, then the
* returned stage completes exceptionally with the supplied
- * action's exception. Or, if this stage completed exceptionally
+ * action's exception. Or, if {@code this} stage completed exceptionally
* and the supplied action throws an exception, then the returned
- * stage completes exceptionally with this stage's exception.
+ * stage completes exceptionally with {@code this} stage's exception.
*
* @param action the action to perform
* @param executor the executor to use for asynchronous execution
@@ -838,14 +852,14 @@ public interface CompletionStage {
Executor executor);
/**
- * Returns a new CompletionStage that, when this stage completes
- * exceptionally, is executed with this stage's exception as the
- * argument to the supplied function. Otherwise, if this stage
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * exceptionally, is executed with {@code this} stage's exception as the
+ * argument to the supplied function. Otherwise, if {@code this} stage
* completes normally, then the returned stage also completes
* normally with the same value.
*
* @param fn the function to use to compute the value of the
- * returned CompletionStage if this CompletionStage completed
+ * returned CompletionStage if {@code this} CompletionStage completed
* exceptionally
* @return the new CompletionStage
*/
@@ -853,10 +867,10 @@ public interface CompletionStage {
(Function fn);
/**
- * Returns a new CompletionStage that, when this stage completes
- * exceptionally, is executed with this stage's exception as the
- * argument to the supplied function, using this stage's default
- * asynchronous execution facility. Otherwise, if this stage
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * exceptionally, is executed with {@code this} stage's exception as the
+ * argument to the supplied function, using {@code this} stage's default
+ * asynchronous execution facility. Otherwise, if {@code this} stage
* completes normally, then the returned stage also completes
* normally with the same value.
*
@@ -865,7 +879,7 @@ public interface CompletionStage {
* #thenCompose} for result.
*
* @param fn the function to use to compute the value of the
- * returned CompletionStage if this CompletionStage completed
+ * returned CompletionStage if {@code this} CompletionStage completed
* exceptionally
* @return the new CompletionStage
* @since 12
@@ -879,10 +893,10 @@ public interface CompletionStage {
}
/**
- * Returns a new CompletionStage that, when this stage completes
- * exceptionally, is executed with this stage's exception as the
+ * Returns a new CompletionStage that, when {@code this} stage completes
+ * exceptionally, is executed with {@code this} stage's exception as the
* argument to the supplied function, using the supplied Executor.
- * Otherwise, if this stage completes normally, then the returned
+ * Otherwise, if {@code this} stage completes normally, then the returned
* stage also completes normally with the same value.
*
* @implSpec The default implementation invokes {@link #handle},
@@ -890,7 +904,7 @@ public interface CompletionStage {
* #thenCompose} for result.
*
* @param fn the function to use to compute the value of the
- * returned CompletionStage if this CompletionStage completed
+ * returned CompletionStage if {@code this} CompletionStage completed
* exceptionally
* @param executor the executor to use for asynchronous execution
* @return the new CompletionStage
@@ -905,16 +919,16 @@ public interface CompletionStage {
}
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* exceptionally, is composed using the results of the supplied
- * function applied to this stage's exception.
+ * function applied to {@code this} stage's exception.
*
* @implSpec The default implementation invokes {@link #handle},
* invoking the given function on exception, then {@link
* #thenCompose} for result.
*
* @param fn the function to use to compute the returned
- * CompletionStage if this CompletionStage completed exceptionally
+ * CompletionStage if {@code this} CompletionStage completed exceptionally
* @return the new CompletionStage
* @since 12
*/
@@ -927,9 +941,9 @@ public interface CompletionStage {
}
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* exceptionally, is composed using the results of the supplied
- * function applied to this stage's exception, using this stage's
+ * function applied to {@code this} stage's exception, using {@code this} stage's
* default asynchronous execution facility.
*
* @implSpec The default implementation invokes {@link #handle},
@@ -937,7 +951,7 @@ public interface CompletionStage {
* #thenCompose} for result.
*
* @param fn the function to use to compute the returned
- * CompletionStage if this CompletionStage completed exceptionally
+ * CompletionStage if {@code this} CompletionStage completed exceptionally
* @return the new CompletionStage
* @since 12
*/
@@ -951,9 +965,9 @@ public interface CompletionStage {
}
/**
- * Returns a new CompletionStage that, when this stage completes
+ * Returns a new CompletionStage that, when {@code this} stage completes
* exceptionally, is composed using the results of the supplied
- * function applied to this stage's exception, using the
+ * function applied to {@code this} stage's exception, using the
* supplied Executor.
*
* @implSpec The default implementation invokes {@link #handle},
@@ -961,7 +975,7 @@ public interface CompletionStage {
* #thenCompose} for result.
*
* @param fn the function to use to compute the returned
- * CompletionStage if this CompletionStage completed exceptionally
+ * CompletionStage if {@code this} CompletionStage completed exceptionally
* @param executor the executor to use for asynchronous execution
* @return the new CompletionStage
* @since 12
@@ -978,9 +992,9 @@ public interface CompletionStage {
/**
* Returns a {@link CompletableFuture} maintaining the same
- * completion properties as this stage. If this stage is already a
- * CompletableFuture, this method may return this stage itself.
- * Otherwise, invocation of this method may be equivalent in
+ * completion properties as {@code this} stage. If {@code this} stage is already a
+ * CompletableFuture, method {@code toCompletableFuture} may return {@code this} stage itself.
+ * Otherwise, invocation may be equivalent in
* effect to {@code thenApply(x -> x)}, but returning an instance
* of type {@code CompletableFuture}.
*
diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
index 8734980cf80..b9df942fbfd 100644
--- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
+++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
@@ -147,7 +147,7 @@ import jdk.internal.vm.annotation.Stable;
* Like {@link Hashtable} but unlike {@link HashMap}, this class
* does not allow {@code null} to be used as a key or value.
*
- *
ConcurrentHashMaps support a set of sequential and parallel bulk
+ *
ConcurrentHashMaps support a set of sequential and parallel bulk
* operations that, unlike most {@link Stream} methods, are designed
* to be safely, and often sensibly, applied even with maps that are
* being concurrently updated by other threads; for example, when
@@ -3704,7 +3704,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each (key, value).
+ * Performs the given {@linkplain ##Bulk bulk} action for each (key, value).
*
* @param parallelismThreshold the (estimated) number of elements
* needed for this operation to be executed in parallel
@@ -3720,7 +3720,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each non-null transformation
+ * Performs the given {@linkplain ##Bulk bulk} action for each non-null transformation
* of each (key, value).
*
* @param parallelismThreshold the (estimated) number of elements
@@ -3743,7 +3743,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns a non-null result from applying the given search
+ * Returns a non-null result from applying the given {@linkplain ##Bulk bulk} search
* function on each (key, value), or null if none. Upon
* success, further element processing is suppressed and the
* results of any other parallel invocations of the search
@@ -3767,7 +3767,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of accumulating the given {@linkplain ##Bulk bulk} transformation
* of all (key, value) pairs using the given reducer to
* combine values, or null if none.
*
@@ -3793,7 +3793,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of accumulating the given {@linkplain ##Bulk bulk} transformation
* of all (key, value) pairs using the given reducer to
* combine values, and the given basis as an identity value.
*
@@ -3819,7 +3819,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of accumulating the given {@linkplain ##Bulk bulk} transformation
* of all (key, value) pairs using the given reducer to
* combine values, and the given basis as an identity value.
*
@@ -3845,7 +3845,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of accumulating the given {@linkplain ##Bulk bulk} transformation
* of all (key, value) pairs using the given reducer to
* combine values, and the given basis as an identity value.
*
@@ -3871,7 +3871,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each key.
+ * Performs the given {@linkplain ##Bulk bulk} action for each key.
*
* @param parallelismThreshold the (estimated) number of elements
* needed for this operation to be executed in parallel
@@ -3887,7 +3887,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each non-null transformation
+ * Performs the given {@linkplain ##Bulk bulk} action for each non-null transformation
* of each key.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -3910,7 +3910,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns a non-null result from applying the given search
+ * Returns a non-null result from applying the given {@linkplain ##Bulk bulk} search
* function on each key, or null if none. Upon success,
* further element processing is suppressed and the results of
* any other parallel invocations of the search function are
@@ -3934,7 +3934,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating all keys using the given
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating all keys using the given
* reducer to combine values, or null if none.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -3953,7 +3953,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all keys using the given reducer to combine values, or
* null if none.
*
@@ -3979,7 +3979,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all keys using the given reducer to combine values, and
* the given basis as an identity value.
*
@@ -4005,7 +4005,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all keys using the given reducer to combine values, and
* the given basis as an identity value.
*
@@ -4031,7 +4031,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all keys using the given reducer to combine values, and
* the given basis as an identity value.
*
@@ -4057,7 +4057,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each value.
+ * Performs the given {@linkplain ##Bulk bulk} action for each value.
*
* @param parallelismThreshold the (estimated) number of elements
* needed for this operation to be executed in parallel
@@ -4074,7 +4074,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each non-null transformation
+ * Performs the given {@linkplain ##Bulk bulk} action for each non-null transformation
* of each value.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -4097,7 +4097,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns a non-null result from applying the given search
+ * Returns a non-null result from {@linkplain ##Bulk bulk} applying the given search
* function on each value, or null if none. Upon success,
* further element processing is suppressed and the results of
* any other parallel invocations of the search function are
@@ -4121,7 +4121,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating all values using the
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating all values using the
* given reducer to combine values, or null if none.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -4139,7 +4139,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all values using the given reducer to combine values, or
* null if none.
*
@@ -4165,7 +4165,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all values using the given reducer to combine values,
* and the given basis as an identity value.
*
@@ -4191,7 +4191,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all values using the given reducer to combine values,
* and the given basis as an identity value.
*
@@ -4217,7 +4217,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all values using the given reducer to combine values,
* and the given basis as an identity value.
*
@@ -4243,7 +4243,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each entry.
+ * Performs the given {@linkplain ##Bulk bulk} action for each entry.
*
* @param parallelismThreshold the (estimated) number of elements
* needed for this operation to be executed in parallel
@@ -4258,7 +4258,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Performs the given action for each non-null transformation
+ * Performs the given {@linkplain ##Bulk bulk} action for each non-null transformation
* of each entry.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -4281,7 +4281,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns a non-null result from applying the given search
+ * Returns a non-null result from {@linkplain ##Bulk bulk} applying the given search
* function on each entry, or null if none. Upon success,
* further element processing is suppressed and the results of
* any other parallel invocations of the search function are
@@ -4305,7 +4305,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating all entries using the
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating all entries using the
* given reducer to combine values, or null if none.
*
* @param parallelismThreshold the (estimated) number of elements
@@ -4323,7 +4323,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all entries using the given reducer to combine values,
* or null if none.
*
@@ -4349,7 +4349,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all entries using the given reducer to combine values,
* and the given basis as an identity value.
*
@@ -4375,7 +4375,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all entries using the given reducer to combine values,
* and the given basis as an identity value.
*
@@ -4401,7 +4401,7 @@ public class ConcurrentHashMap extends AbstractMap
}
/**
- * Returns the result of accumulating the given transformation
+ * Returns the result of {@linkplain ##Bulk bulk} accumulating the given transformation
* of all entries using the given reducer to combine values,
* and the given basis as an identity value.
*
diff --git a/src/java.base/share/classes/java/util/concurrent/CyclicBarrier.java b/src/java.base/share/classes/java/util/concurrent/CyclicBarrier.java
index 87e498d9c24..ca78c254624 100644
--- a/src/java.base/share/classes/java/util/concurrent/CyclicBarrier.java
+++ b/src/java.base/share/classes/java/util/concurrent/CyclicBarrier.java
@@ -44,7 +44,10 @@ import java.util.concurrent.locks.ReentrantLock;
* useful in programs involving a fixed sized party of threads that
* must occasionally wait for each other. The barrier is called
* cyclic because it can be re-used after the waiting threads
- * are released.
+ * are released. If you need support for variable numbers of parties
+ * per cycle, alternate actions on exceptions, termination control,
+ * contention control, or status monitoring, use the more flexible
+ * {@link Phaser} class.
*
* A {@code CyclicBarrier} supports an optional {@link Runnable} command
* that is run once per barrier point, after the last thread in the party
diff --git a/src/java.base/share/classes/java/util/concurrent/ExecutorService.java b/src/java.base/share/classes/java/util/concurrent/ExecutorService.java
index 0d4acf8913e..f899b56b288 100644
--- a/src/java.base/share/classes/java/util/concurrent/ExecutorService.java
+++ b/src/java.base/share/classes/java/util/concurrent/ExecutorService.java
@@ -56,7 +56,9 @@ import java.util.List;
*
*
Method {@code submit} extends base method {@link
* Executor#execute(Runnable)} by creating and returning a {@link Future}
- * that can be used to cancel execution and/or wait for completion.
+ * that can be used to cancel execution and/or wait for completion;
+ * also reporting exceptions that would otherwise be uncaught
+ * using method {@code execute}.
* Methods {@code invokeAny} and {@code invokeAll} perform the most
* commonly useful forms of bulk execution, executing a collection of
* tasks and then waiting for at least one, or all, to
diff --git a/src/java.base/share/classes/java/util/concurrent/Executors.java b/src/java.base/share/classes/java/util/concurrent/Executors.java
index ba7c2e1efee..ef3d6348010 100644
--- a/src/java.base/share/classes/java/util/concurrent/Executors.java
+++ b/src/java.base/share/classes/java/util/concurrent/Executors.java
@@ -306,7 +306,7 @@ public final class Executors {
}
/**
- * Creates a thread pool that can schedule commands to run after a
+ * Creates a fixed-size thread pool that can schedule commands to run after a
* given delay, or to execute periodically.
* @param corePoolSize the number of threads to keep in the pool,
* even if they are idle
@@ -318,7 +318,7 @@ public final class Executors {
}
/**
- * Creates a thread pool that can schedule commands to run after a
+ * Creates a fixed-size thread pool that can schedule commands to run after a
* given delay, or to execute periodically.
* @param corePoolSize the number of threads to keep in the pool,
* even if they are idle
diff --git a/src/java.base/share/classes/java/util/concurrent/Flow.java b/src/java.base/share/classes/java/util/concurrent/Flow.java
index 1aefaea43b0..16b2ba5e9d8 100644
--- a/src/java.base/share/classes/java/util/concurrent/Flow.java
+++ b/src/java.base/share/classes/java/util/concurrent/Flow.java
@@ -60,7 +60,8 @@ package java.util.concurrent;
* TRUE} item to a single subscriber. Because the subscriber receives
* only a single item, this class does not use buffering and ordering
* control required in most implementations (for example {@link
- * SubmissionPublisher}).
+ * SubmissionPublisher}), and omits some error processing needed to
+ * fully conform to the Reactive Streams specification.
*
*
{@code
* class OneShotPublisher implements Publisher {
diff --git a/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java b/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java
index a7821921bc9..482fe3cf801 100644
--- a/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java
+++ b/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java
@@ -140,7 +140,7 @@ import static java.util.concurrent.DelayScheduler.ScheduledForkJoinTask;
* tasks, as well as method {@link #submitWithTimeout} to cancel tasks
* that take too long. The scheduled functions or actions may create
* and invoke other {@linkplain ForkJoinTask ForkJoinTasks}. Delayed
- * actions become enabled and behave as ordinary submitted
+ * actions become enabled for execution and behave as ordinary submitted
* tasks when their delays elapse. Scheduling methods return
* {@linkplain ForkJoinTask ForkJoinTasks} that implement the {@link
* ScheduledFuture} interface. Resource exhaustion encountered after
@@ -153,7 +153,7 @@ import static java.util.concurrent.DelayScheduler.ScheduledForkJoinTask;
* to disable all delayed tasks upon shutdown, and method {@link
* #shutdownNow} may be used to instead unconditionally initiate pool
* termination. Monitoring methods such as {@link #getQueuedTaskCount}
- * do not include scheduled tasks that are not yet enabled to execute,
+ * do not include scheduled tasks that are not yet enabled for execution,
* which are reported separately by method {@link
* #getDelayedTaskCount}.
*
@@ -3505,7 +3505,7 @@ public class ForkJoinPool extends AbstractExecutorService
}
/**
- * Submits a one-shot task that becomes enabled after the given
+ * Submits a one-shot task that becomes enabled for execution after the given
* delay. At that point it will execute unless explicitly
* cancelled, or fail to execute (eventually reporting
* cancellation) when encountering resource exhaustion, or the
@@ -3533,7 +3533,7 @@ public class ForkJoinPool extends AbstractExecutorService
}
/**
- * Submits a value-returning one-shot task that becomes enabled
+ * Submits a value-returning one-shot task that becomes enabled for execution
* after the given delay. At that point it will execute unless
* explicitly cancelled, or fail to execute (eventually reporting
* cancellation) when encountering resource exhaustion, or the
@@ -3562,7 +3562,7 @@ public class ForkJoinPool extends AbstractExecutorService
}
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given period;
* that is, executions will commence after
* {@code initialDelay}, then {@code initialDelay + period}, then
@@ -3616,7 +3616,7 @@ public class ForkJoinPool extends AbstractExecutorService
}
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given delay
* between the termination of one execution and the commencement of
* the next.
diff --git a/src/java.base/share/classes/java/util/concurrent/Future.java b/src/java.base/share/classes/java/util/concurrent/Future.java
index c6f3036c2d2..2ac837d7270 100644
--- a/src/java.base/share/classes/java/util/concurrent/Future.java
+++ b/src/java.base/share/classes/java/util/concurrent/Future.java
@@ -50,6 +50,26 @@ package java.util.concurrent;
* declare types of the form {@code Future>} and
* return {@code null} as a result of the underlying task.
*
+ * Cancellation of a Future need not abruptly terminate its
+ * computation. Method {@code cancel} causes {@code isCancelled()} to
+ * return {@code true} unless already {@code isDone()}; in either case
+ * {@code isDone()} subsequently reports {@code true}. This suppresses
+ * execution by an {@link ExecutorService} if not already started.
+ * There are several options for suppressing unnecessary computation
+ * or unblocking a running Future that will not generate a
+ * result. When task bodies are simple and short, no special attention
+ * is warranted. Computational methods in Future-aware code bodies
+ * (for example {@link ForkJoinTask}, {@link FutureTask}) may inspect
+ * their own {@code isDone()} status before or while engaging in
+ * expensive computations. In blocking I/O or communication contexts,
+ * the optional {@code mayInterruptIfRunning} argument of {@code
+ * cancel} may be used to support conventions that tasks should
+ * unblock and exit when {@link Thread#interrupted}, whether checked
+ * inside a task body or as a response to an {@link
+ * InterruptedException}. It is still preferable to additionally
+ * check {@code isDone()} status when possible to avoid unintended
+ * effects of other uses of {@link Thread#interrupt}.
+ *
*
Sample Usage (Note that the following classes are all
* made-up.)
*
diff --git a/src/java.base/share/classes/java/util/concurrent/FutureTask.java b/src/java.base/share/classes/java/util/concurrent/FutureTask.java
index b905e71aeef..2ec97629105 100644
--- a/src/java.base/share/classes/java/util/concurrent/FutureTask.java
+++ b/src/java.base/share/classes/java/util/concurrent/FutureTask.java
@@ -285,7 +285,9 @@ public class FutureTask implements RunnableFuture {
* this future has already been set or has been cancelled.
*
* This method is invoked internally by the {@link #run} method
- * upon successful completion of the computation.
+ * upon successful completion of the computation. Invocation in
+ * other contexts has undefined effects. Any override of this
+ * method in subclasses should include {@code super.set(v)}.
*
* @param v the value
*/
diff --git a/src/java.base/share/classes/java/util/concurrent/RunnableFuture.java b/src/java.base/share/classes/java/util/concurrent/RunnableFuture.java
index b6b088ae7cd..8585cfe1082 100644
--- a/src/java.base/share/classes/java/util/concurrent/RunnableFuture.java
+++ b/src/java.base/share/classes/java/util/concurrent/RunnableFuture.java
@@ -47,8 +47,9 @@ package java.util.concurrent;
*/
public interface RunnableFuture extends Runnable, Future {
/**
- * Sets this Future to the result of its computation
- * unless it has been cancelled.
+ * Sets this Future to the result of its computation unless it has
+ * been cancelled (or has already been invoked, in which case
+ * effects are undefined).
*/
void run();
}
diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledExecutorService.java b/src/java.base/share/classes/java/util/concurrent/ScheduledExecutorService.java
index 4d63ffae4bb..034d98687c2 100644
--- a/src/java.base/share/classes/java/util/concurrent/ScheduledExecutorService.java
+++ b/src/java.base/share/classes/java/util/concurrent/ScheduledExecutorService.java
@@ -40,10 +40,12 @@ package java.util.concurrent;
* delay, or to execute periodically.
*
* The {@code schedule} methods create tasks with various delays
- * and return a task object that can be used to cancel or check
- * execution. The {@code scheduleAtFixedRate} and
- * {@code scheduleWithFixedDelay} methods create and execute tasks
- * that run periodically until cancelled.
+ * and return {@link ScheduledFuture} objects that can be used to cancel or check
+ * execution. When delays elapse, tasks are enabled for execution and
+ * behave in accord with other {@link ExecutorService} tasks, except
+ * that {@code scheduleAtFixedRate} and {@code scheduleWithFixedDelay}
+ * methods create and execute tasks that run periodically until
+ * cancelled.
*
*
Commands submitted using the {@link Executor#execute(Runnable)}
* and {@link ExecutorService} {@code submit} methods are scheduled
@@ -91,7 +93,7 @@ package java.util.concurrent;
public interface ScheduledExecutorService extends ExecutorService {
/**
- * Submits a one-shot task that becomes enabled after the given delay.
+ * Submits a one-shot task that becomes enabled for execution after the given delay.
*
* @param command the task to execute
* @param delay the time from now to delay execution
@@ -107,7 +109,7 @@ public interface ScheduledExecutorService extends ExecutorService {
long delay, TimeUnit unit);
/**
- * Submits a value-returning one-shot task that becomes enabled
+ * Submits a value-returning one-shot task that becomes enabled for execution
* after the given delay.
*
* @param callable the function to execute
@@ -123,7 +125,7 @@ public interface ScheduledExecutorService extends ExecutorService {
long delay, TimeUnit unit);
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given period;
* that is, executions will commence after
* {@code initialDelay}, then {@code initialDelay + period}, then
@@ -167,7 +169,7 @@ public interface ScheduledExecutorService extends ExecutorService {
TimeUnit unit);
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given delay
* between the termination of one execution and the commencement of
* the next.
diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java
index 94f40ccf6f5..23398aeae28 100644
--- a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java
+++ b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java
@@ -57,7 +57,7 @@ import java.util.concurrent.locks.ReentrantLock;
* capabilities of {@link ThreadPoolExecutor} (which this class
* extends) are required.
*
- *
Delayed tasks execute no sooner than they are enabled, but
+ *
Delayed tasks execute no sooner than they are enabled for execution, but
* without any real-time guarantees about when, after they are
* enabled, they will commence. Tasks scheduled for exactly the same
* execution time are enabled in first-in-first-out (FIFO) order of
@@ -568,7 +568,7 @@ public class ScheduledThreadPoolExecutor
}
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given period;
* that is, executions will commence after
* {@code initialDelay}, then {@code initialDelay + period}, then
@@ -621,7 +621,7 @@ public class ScheduledThreadPoolExecutor
}
/**
- * Submits a periodic action that becomes enabled first after the
+ * Submits a periodic action that becomes enabled for execution first after the
* given initial delay, and subsequently with the given delay
* between the termination of one execution and the commencement of
* the next.
diff --git a/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java b/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java
index 3a8f3746637..f793d2bcabd 100644
--- a/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java
+++ b/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java
@@ -162,8 +162,8 @@ import static java.util.concurrent.Flow.Subscription;
* (this.subscription = subscription).request(1);
* }
* public void onNext(S item) {
- * subscription.request(1);
* submit(function.apply(item));
+ * subscription.request(1);
* }
* public void onError(Throwable ex) { closeExceptionally(ex); }
* public void onComplete() { close(); }
@@ -602,9 +602,11 @@ public class SubmissionPublisher implements Publisher,
/**
* Unless already closed, issues {@link
* Flow.Subscriber#onComplete() onComplete} signals to current
- * subscribers, and disallows subsequent attempts to publish.
- * Upon return, this method does NOT guarantee that all
- * subscribers have yet completed.
+ * subscribers, and disallows subsequent attempts to publish. To
+ * ensure uniform ordering among subscribers, this method may
+ * await completion of in-progress offers. Upon return, this
+ * method does NOT guarantee that all subscribers have
+ * yet completed.
*/
public void close() {
ReentrantLock lock = this.lock;
diff --git a/src/java.base/share/classes/java/util/concurrent/TimeUnit.java b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
index f02aa9f5931..d116fb9b22b 100644
--- a/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
+++ b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
@@ -398,6 +398,8 @@ public enum TimeUnit {
* @param obj the object to wait on
* @param timeout the maximum time to wait. If less than
* or equal to zero, do not wait at all.
+ * @throws IllegalMonitorStateException if the current thread is not
+ * the owner of the object's monitor.
* @throws InterruptedException if interrupted while waiting
*/
public void timedWait(Object obj, long timeout)
diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
index e01b3ec7d50..f947eb4f7db 100644
--- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
+++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
@@ -46,10 +46,11 @@ import java.lang.invoke.VarHandle;
/**
* A reflection-based utility that enables atomic updates to
- * designated {@code volatile int} fields of designated classes.
- * This class is designed for use in atomic data structures in which
- * several fields of the same node are independently subject to atomic
- * updates.
+ * designated non-static {@code volatile int} fields of designated
+ * classes, providing a subset of the functionality of class {@link
+ * VarHandle} that should be used instead. This class is designed for
+ * use in atomic data structures in which several fields of the same
+ * node are independently subject to atomic updates.
*
* Note that the guarantees of the {@code compareAndSet}
* method in this class are weaker than in other atomic classes.
diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
index 57722f33371..b31a8edf53a 100644
--- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
+++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
@@ -46,10 +46,11 @@ import java.lang.invoke.VarHandle;
/**
* A reflection-based utility that enables atomic updates to
- * designated {@code volatile long} fields of designated classes.
- * This class is designed for use in atomic data structures in which
- * several fields of the same node are independently subject to atomic
- * updates.
+ * designated non-static {@code volatile long} fields of designated
+ * classes, providing a subset of the functionality of class {@link
+ * VarHandle} that should be used instead. This class is designed for
+ * use in atomic data structures in which several fields of the same
+ * node are independently subject to atomic updates.
*
*
Note that the guarantees of the {@code compareAndSet}
* method in this class are weaker than in other atomic classes.
diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
index 1c0c6d0afd0..e3ca4830d5a 100644
--- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
+++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
@@ -46,11 +46,12 @@ import java.lang.invoke.VarHandle;
/**
* A reflection-based utility that enables atomic updates to
- * designated {@code volatile} reference fields of designated
- * classes. This class is designed for use in atomic data structures
- * in which several reference fields of the same node are
- * independently subject to atomic updates. For example, a tree node
- * might be declared as
+ * designated non-static {@code volatile} reference fields of
+ * designated classes, providing a subset of the functionality of
+ * class {@link VarHandle} that should be used instead. This class
+ * may be used in atomic data structures in which several reference
+ * fields of the same node are independently subject to atomic
+ * updates. For example, a tree node might be declared as
*
*
{@code
* class Node {
@@ -68,6 +69,26 @@ import java.lang.invoke.VarHandle;
* // ... and so on
* }}
*
+ * However, it is preferable to use {@link VarHandle}:
+ * {@code
+ * import java.lang.invoke.VarHandle;
+ * import java.lang.invoke.MethodHandles;
+ * class Node {
+ * private volatile Node left, right;
+ * private static final VarHandle LEFT, RIGHT;
+ * Node getLeft() { return left; }
+ * boolean compareAndSetLeft(Node expect, Node update) {
+ * return LEFT.compareAndSet(this, expect, update);
+ * }
+ * // ... and so on
+ * static { try {
+ * MethodHandles.Lookup l = MethodHandles.lookup();
+ * LEFT = l.findVarHandle(Node.class, "left", Node.class);
+ * RIGHT = l.findVarHandle(Node.class, "right", Node.class);
+ * } catch (ReflectiveOperationException e) {
+ * throw new ExceptionInInitializerError(e);
+ * }}}}
+ *
* Note that the guarantees of the {@code compareAndSet}
* method in this class are weaker than in other atomic classes.
* Because this class cannot ensure that all uses of the field
diff --git a/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java b/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java
index 3e0b293380f..536996fd273 100644
--- a/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java
+++ b/src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java
@@ -97,6 +97,10 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
* perform reads under read locks. If a reader tries to acquire the
* write lock it will never succeed.
*
+ *
Note: If you do not rely on reentrancy, you may find that {@link
+ * StampedLock} offers better performance, as in: {@code ReadWriteLock
+ * lock = new StampedLock().asReadWriteLock()}.
+ *
*
- Lock downgrading
*
Reentrancy also allows downgrading from the write lock to a read lock,
* by acquiring the write lock, then the read lock and then releasing the
@@ -734,11 +738,13 @@ public class ReentrantReadWriteLock
* Acquires the read lock.
*
*
Acquires the read lock if the write lock is not held by
- * another thread and returns immediately.
+ * any thread and returns immediately.
*
- *
If the write lock is held by another thread then
- * the current thread becomes disabled for thread scheduling
- * purposes and lies dormant until the read lock has been acquired.
+ *
If the write lock is held by any thread or the fairness
+ * policy prohibits acquisition of the read lock at this time,
+ * then the current thread becomes disabled for thread
+ * scheduling purposes and lies dormant until the read lock
+ * has been acquired.
*/
public void lock() {
sync.acquireShared(1);
@@ -749,11 +755,13 @@ public class ReentrantReadWriteLock
* {@linkplain Thread#interrupt interrupted}.
*
*
Acquires the read lock if the write lock is not held
- * by another thread and returns immediately.
+ * by any thread and returns immediately.
*
- *
If the write lock is held by another thread then the
- * current thread becomes disabled for thread scheduling
- * purposes and lies dormant until one of two things happens:
+ *
If the write lock is held by any thread or the fairness
+ * policy prohibits acquisition of the read lock at this time,
+ * then the current thread becomes disabled for thread
+ * scheduling purposes and lies dormant until one of two
+ * things happens:
*
*
*
@@ -794,7 +802,7 @@ public class ReentrantReadWriteLock
* another thread at the time of invocation.
*
* Acquires the read lock if the write lock is not held by
- * another thread and returns immediately with the value
+ * any thread and returns immediately with the value
* {@code true}. Even when this lock has been set to use a
* fair ordering policy, a call to {@code tryLock()}
* will immediately acquire the read lock if it is
@@ -806,7 +814,7 @@ public class ReentrantReadWriteLock
* tryLock(0, TimeUnit.SECONDS)} which is almost equivalent
* (it also detects interruption).
*
- *
If the write lock is held by another thread then
+ *
If the write lock is held by any thread then
* this method will return immediately with the value
* {@code false}.
*
diff --git a/src/java.base/share/classes/java/util/concurrent/package-info.java b/src/java.base/share/classes/java/util/concurrent/package-info.java
index dd0c8f79bc0..f237017799d 100644
--- a/src/java.base/share/classes/java/util/concurrent/package-info.java
+++ b/src/java.base/share/classes/java/util/concurrent/package-info.java
@@ -222,7 +222,9 @@
*
- they are guaranteed to traverse elements as they existed upon
* construction exactly once, and may (but are not guaranteed to)
* reflect any modifications subsequent to construction.
- *
+ * - These properties extend to other iteration-based
+ * operations. In particular, {@link Object#equals} is almost never
+ * useful unless both collections are known to be quiescent.
*
*
Memory Consistency Properties
*