Skip to content

Commit 65f1940

Browse files
committed
lecture
1 parent 4adca73 commit 65f1940

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/io/concurrency/chapter11/exam10/completeExceptionallyExample.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
public class completeExceptionallyExample {
66
public static void main(String[] args) {
77

8-
CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> "Hello World");
8+
CompletableFuture<String> cf1 = new CompletableFuture<>();
99
getData(cf1);
10-
1110
CompletableFuture<String> cf2 = cf1
1211
.thenApply(result -> {
1312
System.out.println(result);
@@ -21,15 +20,17 @@ public static void main(String[] args) {
2120
return r;
2221
});
2322

24-
2523
System.out.println("result: " + cf2.join());
2624
}
2725

28-
static void getData(CompletableFuture<String> future) {
26+
private static void getData(CompletableFuture<String> cf1) {
2927
try {
30-
throw new RuntimeException("error");
31-
} catch (RuntimeException e) {
32-
future.completeExceptionally(e);
28+
System.out.println("비동기 작업 수행중");
29+
Thread.sleep(100);
30+
throw new IllegalArgumentException("error");
31+
} catch (Exception e) {
32+
cf1.completeExceptionally(e);
3333
}
34+
cf1.complete("Hello World");
3435
}
35-
}
36+
}

0 commit comments

Comments
 (0)