forked from guanpengchn/java-concurrent-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
23 lines (20 loc) · 699 Bytes
/
Copy pathExample3.java
File metadata and controls
23 lines (20 loc) · 699 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 Example3 {
public static Integer calc(Integer para){
try{
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return para * para;
}
public static void main(String []args) throws ExecutionException, InterruptedException {
CompletableFuture<Void> fu=CompletableFuture.supplyAsync(()->calc(50))
.thenApply((i)->Integer.toString(i))
.thenApply((str)->"\""+str+"\"")
.thenAccept(System.out::println);
fu.get();
}
}