|
|
@@ -28,6 +28,7 @@ public class Cf04_ThenEither {
|
|
|
CompletableFuture<Void> r1 = CompletableFuture.runAsync(() -> sleep(60));
|
|
|
CompletableFuture<Void> r2 = CompletableFuture.runAsync(() -> sleep(500));
|
|
|
r1.runAfterEither(r2, () -> System.out.println("runAfterEither: 有一路先完成了")).join();
|
|
|
+ r2.join(); // 等待较慢的一路也结束,避免 main 退出时打断它
|
|
|
}
|
|
|
|
|
|
private static void sleep(long ms) {
|