Skip to content

Commit b11ea94

Browse files
committed
lecture
1 parent bcc67ec commit b11ea94

File tree

3 files changed

+7
-71
lines changed

3 files changed

+7
-71
lines changed

src/main/java/io/concurrency/chapter11/exam05/ThenApplyExample.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,28 @@ public static void main(String[] args) {
77

88
MyService myService = new MyService();
99
CompletableFuture<Integer> asyncFuture = CompletableFuture.supplyAsync(() -> {
10-
try {
11-
Thread.sleep(1000);
12-
} catch (InterruptedException e) {
13-
Thread.currentThread().interrupt();
14-
}
10+
System.out.println("thread1:" + Thread.currentThread().getName());
1511
return 40;
1612
})
1713
.thenApply(result -> {
1814
int r = myService.getData1();
19-
System.out.println("thread:" + Thread.currentThread().getName());
15+
System.out.println("thread2:" + Thread.currentThread().getName());
2016
return r + result;
21-
}).thenApplyAsync(result -> {
17+
}).thenApply(result -> {
2218
int r = myService.getData2();
23-
System.out.println("thread:" + Thread.currentThread().getName());
19+
System.out.println("thread3:" + Thread.currentThread().getName());
2420
return r + result;
2521
});
2622

27-
int asyncResult = asyncFuture.join(); // 가공된 비동기 작업 결과를 얻음
23+
int asyncResult = asyncFuture.join();
2824
System.out.println("final result: " + asyncResult);
2925
}
3026

3127
static class MyService {
3228

3329
public int getData1(){
3430
try {
35-
Thread.sleep(1000);
31+
Thread.sleep(500);
3632
} catch (InterruptedException e) {
3733
throw new RuntimeException(e);
3834
}
@@ -41,7 +37,7 @@ public int getData1(){
4137

4238
public int getData2(){
4339
try {
44-
Thread.sleep(1000);
40+
Thread.sleep(500);
4541
} catch (InterruptedException e) {
4642
throw new RuntimeException(e);
4743
}

src/main/java/io/concurrency/chapter11/exam05/ThenApplyThreadExample.java

-28
This file was deleted.

src/main/java/io/concurrency/chapter11/exam05/ThenApplyThreadExample2.java

-32
This file was deleted.

0 commit comments

Comments
 (0)