Concurrency Coordination Reports
Future Chain Coordination Report
Chain transformations onto an already-completed future and classify the result.
Future Chain Coordination Report
FutureChainCoordinationReport.java
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class FutureChainCoordinationReport {
public static void main(String[] args) throws InterruptedException, ExecutionException {
int seed = ;
CompletableFuture<Integer> future = CompletableFuture
.completedFuture(seed)
.thenApply(value -> value * 2)
.thenApply(value -> value + 1);
int result = future.get();
String status = result <= 3 ? "small" : result <= 9 ? "mid" : "large";
System.out.println("seed=" + seed + " result=" + result + " status=" + status);
}
}
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class FutureChainCoordinationReport {
public static void main(String[] args) throws InterruptedException, ExecutionException {
int seed = ;
CompletableFuture<Integer> future = CompletableFuture
.completedFuture(seed)
.thenApply(value -> value * 2)
.thenApply(value -> value + 1);
int result = future.get();
String status = result <= 3 ? "small" : result <= 9 ? "mid" : "large";
System.out.println("seed=" + seed + " result=" + result + " status=" + status);
}
}
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class FutureChainCoordinationReport {
public static void main(String[] args) throws InterruptedException, ExecutionException {
int seed = ;
CompletableFuture<Integer> future = CompletableFuture
.completedFuture(seed)
.thenApply(value -> value * 2)
.thenApply(value -> value + 1);
int result = future.get();
String status = result <= 3 ? "small" : result <= 9 ? "mid" : "large";
System.out.println("seed=" + seed + " result=" + result + " status=" + status);
}
}
completable future
A `CompletableFuture` that is already completed runs each `thenApply` stage in order, so a chain stays deterministic and its final value can be reported.