From 1e1ba844616c376ad16cbacb07d8cb530aa87137 Mon Sep 17 00:00:00 2001 From: Doug Lea
{@code
+ * stage.thenApply(x -> square(x))
+ * .thenAccept(x -> System.out.print(x))
+ * .thenRun(() -> System.out.println());}
+ *
+ * An additional form (compose) allows the construction of
+ * computation pipelines from functions returning completion stages.
+ *
+ * Any argument to a stage's computation is the outcome of a + * triggering stage's computation. * *
Method form {@link #handle handle} is the most general way of + * creating a continuation stage, unconditionally performing a + * computation that is given both the result and exception (if any) of + * the triggering CompletionStage, and computing an arbitrary result. + * Method {@link #whenComplete whenComplete} is similar, but preserves + * the result of the triggering stage instead of computing a new one. + * Because a stage's normal result may be {@code null}, both methods + * should have a computation structured thus: + * + *
{@code (result, exception) -> {
+ * if (exception == null) {
+ * // triggering stage completed normally
+ * } else {
+ * // triggering stage completed exceptionally
+ * }
+ * }}
+ *
* This interface does not define methods for initially creating,
* forcibly completing normally or exceptionally, probing completion
* status or results, or awaiting completion of a stage.
@@ -129,11 +155,15 @@ public interface CompletionStage This method is analogous to
+ * {@link java.util.Optional#map Optional.map} and
+ * {@link java.util.stream.Stream#map Stream.map}.
+ *
+ * See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
*
- * @param fn the function to use to compute the value of
- * the returned CompletionStage
+ * @param fn the function to use to compute the value of the
+ * returned CompletionStage
* @param the function's return type
* @return the new CompletionStage
*/
@@ -148,8 +178,8 @@ public interface CompletionStage When this stage completes normally, the given function is
+ * invoked with 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 same value.
+ *
+ * To ensure progress, the supplied function must arrange
+ * eventual completion of its result.
+ *
+ * This method is analogous to
+ * {@link java.util.Optional#flatMap Optional.flatMap} and
+ * {@link java.util.stream.Stream#flatMap Stream.flatMap}.
+ *
+ * See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
*
- * @param fn the function returning a new CompletionStage
+ * @param fn the function to use to compute another CompletionStage
* @param the type of the returned CompletionStage's result
- * @return the CompletionStage
+ * @return the new CompletionStage
*/
public CompletionStage thenCompose
(Function super T, ? extends CompletionStage> 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 the
- * supplied function.
+ * 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
+ * facility.
*
- * See the {@link CompletionStage} documentation for rules
+ * When this stage completes normally, the given function is
+ * invoked with 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 same value.
+ *
+ * To ensure progress, the supplied function must arrange
+ * eventual completion of its result.
+ *
+ * See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
*
- * @param fn the function returning a new CompletionStage
+ * @param fn the function to use to compute another CompletionStage
* @param the type of the returned CompletionStage's result
- * @return the CompletionStage
+ * @return the new CompletionStage
*/
public CompletionStage thenComposeAsync
(Function super T, ? extends CompletionStage> fn);
/**
- * Returns a new CompletionStage that, when this stage completes
- * normally, is executed using the supplied Executor, with this
- * stage's result as the argument to the supplied function.
+ * Returns a new CompletionStage that is completed with the same
+ * value as the CompletionStage returned by the given function,
+ * executed using the supplied Executor.
*
- * See the {@link CompletionStage} documentation for rules
+ * When this stage completes normally, the given function is
+ * invoked with 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 same value.
+ *
+ * To ensure progress, the supplied function must arrange
+ * eventual completion of its result.
+ *
+ * See the {@link CompletionStage} documentation for rules
* covering exceptional completion.
*
- * @param fn the function returning a new CompletionStage
+ * @param fn the function to use to compute another CompletionStage
* @param executor the executor to use for asynchronous execution
* @param the type of the returned CompletionStage's result
- * @return the CompletionStage
+ * @return the new CompletionStage
*/
public CompletionStage thenComposeAsync
(Function super T, ? extends CompletionStage> fn,
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
- * 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
- * exceptionally
- * @return the new CompletionStage
- */
- public CompletionStage When 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 when the action returns. If the supplied
- * action itself encounters an exception, then the returned stage
- * exceptionally completes with this exception unless this stage
- * also completed exceptionally (in which case, the returned stage
- * exceptionally completes with the original exception).
- *
- * @param action the action to perform
- * @return the new CompletionStage
- */
- public CompletionStage When 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
- * when the action returns. If the supplied action itself encounters an
- * exception, then the returned stage exceptionally completes with this
- * exception unless this stage also completed exceptionally.
- *
- * @param action the action to perform
- * @return the new CompletionStage
- */
- public CompletionStage When 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
- * when the action returns. If the supplied action itself encounters an
- * exception, then the returned stage exceptionally completes with this
- * exception unless this stage also completed exceptionally.
- *
- * @param action the action to perform
- * @param executor the executor to use for asynchronous execution
- * @return the new CompletionStage
- */
- public CompletionStage When 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 when the action returns.
+ *
+ * Unlike method {@link #handle handle},
+ * this method 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
+ * 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
+ * and the supplied action throws an exception, then the returned
+ * stage completes exceptionally with this stage's exception.
+ *
+ * @param action the action to perform
+ * @return the new CompletionStage
+ */
+ public CompletionStage When 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
+ * when the action returns.
+ *
+ * Unlike method {@link #handleAsync(BiFunction) handleAsync},
+ * this method 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
+ * 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
+ * and the supplied action throws an exception, then the returned
+ * stage completes exceptionally with this stage's exception.
+ *
+ * @param action the action to perform
+ * @return the new CompletionStage
+ */
+ public CompletionStage When 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
+ * when the action returns.
+ *
+ * Unlike method {@link #handleAsync(BiFunction,Executor) handleAsync},
+ * this method 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
+ * 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
+ * and the supplied action throws an exception, then the returned
+ * stage completes exceptionally with this stage's exception.
+ *
+ * @param action the action to perform
+ * @param executor the executor to use for asynchronous execution
+ * @return the new CompletionStage
+ */
+ public CompletionStage
Date: Tue, 16 Feb 2016 09:52:49 -0800
Subject: [PATCH 2/2] 8145485: Miscellaneous changes imported from jsr166 CVS
2016-02
Reviewed-by: martin, psandoz, chegar
---
.../classes/java/util/SplittableRandom.java | 11 +++--
.../java/util/concurrent/Exchanger.java | 7 ++--
.../java/util/concurrent/ForkJoinPool.java | 5 ++-
.../java/util/concurrent/ForkJoinTask.java | 40 ++++++++-----------
.../util/concurrent/ThreadLocalRandom.java | 11 +++--
.../util/concurrent/atomic/Striped64.java | 14 +++----
.../ConcurrentQueues/RemovePollRace.java | 12 ++++--
.../ExecutorCompletionServiceLoops.java | 4 +-
8 files changed, 50 insertions(+), 54 deletions(-)
diff --git a/jdk/src/java.base/share/classes/java/util/SplittableRandom.java b/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
index 2e08a4ddb87..cf71c91e8da 100644
--- a/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
+++ b/jdk/src/java.base/share/classes/java/util/SplittableRandom.java
@@ -225,14 +225,13 @@ public final class SplittableRandom {
private static final AtomicLong defaultGen = new AtomicLong(initialSeed());
private static long initialSeed() {
- String pp = java.security.AccessController.doPrivileged(
- new sun.security.action.GetPropertyAction(
- "java.util.secureRandomSeed"));
- if (pp != null && pp.equalsIgnoreCase("true")) {
+ java.security.PrivilegedAction