package bunny.async; import java.util.concurrent.CompletableFuture; public class CompletableFutureTest3 { public static void main(String[] args) { CompletableFuture future1 = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future2 = CompletableFuture.supplyAsync(() -> "World"); // 可以传入多个任务(CompletableFuture) // 任意一个任务完成 CompletableFuture anyFuture = CompletableFuture.anyOf(future1, future2); // 阻塞获取结果 Object result = anyFuture.join(); System.out.println("任意一个任务完成: " + result); } }