forked from guanpengchn/java-concurrent-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample6.java
More file actions
19 lines (16 loc) · 700 Bytes
/
Copy pathExample6.java
File metadata and controls
19 lines (16 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package ch6.s5;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Example6 {
public static Integer calc(Integer para){
return para/2;
}
public static void main(String []args) throws ExecutionException, InterruptedException {
CompletableFuture<Integer> intFuture = CompletableFuture.supplyAsync(()->calc(50));
CompletableFuture<Integer> intFuture2 = CompletableFuture.supplyAsync(()->calc(25));
CompletableFuture<Void> fu = intFuture.thenCombine(intFuture2,(i,j)->(i+j))
.thenApply((str)->"\""+str+"\"")
.thenAccept(System.out::println);
fu.get();
}
}