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