19 lines
661 B
Java
19 lines
661 B
Java
|
package bunny.async;
|
||
|
|
||
|
import java.util.concurrent.CompletableFuture;
|
||
|
|
||
|
public class CompletableFutureTest2 {
|
||
|
public static void main(String[] args) throws Exception {
|
||
|
CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> "Hello");
|
||
|
CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> "World");
|
||
|
|
||
|
// 传入所有的任务返回(CompletableFuture)
|
||
|
// 等待所有任务都完成
|
||
|
CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2);
|
||
|
|
||
|
// 阻塞线程
|
||
|
allFutures.join();
|
||
|
System.out.println("所有任务都完成了。。。");
|
||
|
}
|
||
|
}
|