Skip to content

Commit 848517b

Browse files
committed
lecture
1 parent af86cab commit 848517b

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

src/main/java/io/concurrency/chapter11/exam06/ThenAcceptExample.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public static void main(String[] args) {
2020
})
2121
.thenAccept(result -> {
2222
System.out.println("thread2:" + Thread.currentThread().getName());
23+
System.out.println("결과: " + result);
2324
List<Integer> r = myService.getData1();
2425
r.forEach(System.out::println);
2526

2627
}).thenAcceptAsync(result -> {
2728
System.out.println("thread3:" + Thread.currentThread().getName());
29+
System.out.println("결과: " + result);
2830
List<Integer> r = myService.getData2();
2931
r.forEach(System.out::println);
3032

src/main/java/io/concurrency/chapter11/exam06/ThenRunExample.java

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static void main(String[] args) {
3838
System.out.println("모든 작업 완료");
3939

4040
}
41-
4241
static class MyService {
4342

4443
public List<Integer> getData1(){

src/main/java/io/concurrency/chapter11/exam07/ThenCombineExample.java

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

88
MyService myService = new MyService();
99

10-
CompletableFuture<String> cf1 = myService.fetchAsyncData(); // 비동기 작업 1
11-
CompletableFuture<String> cf2 = myService.fetchAsyncData2();
10+
CompletableFuture<String> cf1 = myService.getData1(); // 비동기 작업 1
11+
CompletableFuture<String> cf2 = myService.getData2();
1212

1313
CompletableFuture<String> cf3 = cf1.thenCombine(cf2, (r1, r2) -> r1 + r2);
1414

@@ -19,7 +19,7 @@ public static void main(String[] args){
1919

2020
static class MyService {
2121

22-
public CompletableFuture<String> fetchAsyncData() {
22+
public CompletableFuture<String> getData1() {
2323
return CompletableFuture.supplyAsync(() -> {
2424
try {
2525
Thread.sleep(500); // 2초 동안 대기
@@ -30,7 +30,7 @@ public CompletableFuture<String> fetchAsyncData() {
3030
});
3131
}
3232

33-
public CompletableFuture<String> fetchAsyncData2() {
33+
public CompletableFuture<String> getData2() {
3434
return CompletableFuture.supplyAsync(() -> {
3535
try {
3636
Thread.sleep(500); // 2초 동안 대기
@@ -40,9 +40,5 @@ public CompletableFuture<String> fetchAsyncData2() {
4040
return "World";
4141
});
4242
}
43-
44-
public int performData(int input) {
45-
return input + 10;
46-
}
4743
}
4844
}

src/main/java/io/concurrency/chapter11/exam07/ThenComposeExample.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
99

1010
MyService myService = new MyService();
1111

12-
CompletableFuture<Integer> asyncTask1 = myService.fetchAsyncData(5); // 비동기 작업 1
12+
CompletableFuture<Integer> asyncTask1 = myService.getData1(5); // 비동기 작업 1
1313
CompletableFuture<Integer> asyncTask2 = asyncTask1.thenCompose(result -> {
1414
// 이전 비동기 작업의 결과를 사용 하여 다른 비동기 작업 실행
15-
return myService.fetchAsyncData2(result);
15+
return myService.getData2(result);
1616
});
1717

18-
int finalResult = myService.performData(asyncTask2.get());
18+
int finalResult = asyncTask2.get();
1919

2020
System.out.println("final result: " + finalResult);
2121
}
2222

2323
static class MyService {
2424

25-
public CompletableFuture<Integer> fetchAsyncData(int input) {
25+
public CompletableFuture<Integer> getData1(int input) {
2626
return CompletableFuture.supplyAsync(() -> {
2727
try {
2828
Thread.sleep(500); // 2초 동안 대기
@@ -34,7 +34,7 @@ public CompletableFuture<Integer> fetchAsyncData(int input) {
3434
}
3535

3636
// 호출 되는 함수가 비동기로 실행 된 후 반환 값이 CompletableFuture 로 되는 경우
37-
public CompletableFuture<Integer> fetchAsyncData2(int input) {
37+
public CompletableFuture<Integer> getData2(int input) {
3838
return CompletableFuture.supplyAsync(() -> {
3939
try {
4040
Thread.sleep(500); // 2초 동안 대기
@@ -44,9 +44,5 @@ public CompletableFuture<Integer> fetchAsyncData2(int input) {
4444
return input * 2;
4545
});
4646
}
47-
48-
public int performData(int input) {
49-
return input + 10;
50-
}
5147
}
5248
}

0 commit comments

Comments
 (0)