Chain transformations onto an already-completed future and classify the result.

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.

Future Chain Coordination Report

seed
FutureChainCoordinationReport.java
Replay: real traced execution (multi-file project)
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class FutureChainCoordinationReport {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        int seed = 3;
        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 = 1;
        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 = 6;
        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);
    }
}
  1. seed ← 3, future ← ⟨CompletableFuture A⟩[Completed normally], result ← 7

    4public class FutureChainCoordinationReport {5    public static void main(String[] args) throws InterruptedException, ExecutionException {6        int seed→ 3 = 3;  //@seed=1, 67        CompletableFuture<Integer> future→ ⟨CompletableFuture A⟩[Completed normally] = CompletableFuture8            .completedFuture(seed3)9            .thenApply(value -> value * 2)10            .thenApply(value -> value + 1);1112        int result→ 7 = future.get();13        String status→ mid = result7 <= 3 ? "small" : result <= 9 ? "mid" : "large";1415        System.out.println("seed=" + seed3 + " result=" + result7 + " status=" + statusmid);16    }
    outputseed=3 result=7 status=mid
  1. seed ← 1, future ← ⟨CompletableFuture A⟩[Completed normally], result ← 3

    4public class FutureChainCoordinationReport {5    public static void main(String[] args) throws InterruptedException, ExecutionException {6        int seed→ 1 = 1;7        CompletableFuture<Integer> future→ ⟨CompletableFuture A⟩[Completed normally] = CompletableFuture8            .completedFuture(seed1)9            .thenApply(value -> value * 2)10            .thenApply(value -> value + 1);1112        int result→ 3 = future.get();13        String status→ small = result3 <= 3 ? "small" : result <= 9 ? "mid" : "large";1415        System.out.println("seed=" + seed1 + " result=" + result3 + " status=" + statussmall);16    }
    outputseed=1 result=3 status=small
  1. seed ← 6, future ← ⟨CompletableFuture A⟩[Completed normally], result ← 13

    4public class FutureChainCoordinationReport {5    public static void main(String[] args) throws InterruptedException, ExecutionException {6        int seed→ 6 = 6;7        CompletableFuture<Integer> future→ ⟨CompletableFuture A⟩[Completed normally] = CompletableFuture8            .completedFuture(seed6)9            .thenApply(value -> value * 2)10            .thenApply(value -> value + 1);1112        int result→ 13 = future.get();13        String status→ large = result13 <= 3 ? "small" : result <= 9 ? "mid" : "large";1415        System.out.println("seed=" + seed6 + " result=" + result13 + " status=" + statuslarge);16    }
    outputseed=6 result=13 status=large