Skip to content

Commit 5686c67

Browse files
committed
lecture
1 parent 06289b0 commit 5686c67

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/main/java/io/concurrency/chapter11/exam04/RunAsyncExample.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
import java.util.concurrent.CompletableFuture;
66

77
public class RunAsyncExample {
8-
98
public static void main(String[] args) {
109

1110
MyService myService = new MyService();
11+
1212
CompletableFuture.runAsync(() -> {
1313

14-
List<Integer> list = myService.getData();
15-
list.stream().forEach(System.out::println);
14+
System.out.println(Thread.currentThread().getName() + " 가 비동기 작업을 시작 합니다.");
15+
List<Integer> result = myService.getData();
1616

17-
}).join();
18-
19-
System.out.println("메인 작업 종료");
17+
result.stream().forEach(System.out::println);
2018

19+
}).join();
2120
}
2221

2322
static class MyService {
@@ -30,7 +29,7 @@ public List<Integer> getData() {
3029
result.add(3);
3130

3231
try {
33-
Thread.sleep(1000); // 비동기 작업 시간 지연 시뮬레이션
32+
Thread.sleep(1000);
3433
} catch (InterruptedException e) {
3534
Thread.currentThread().interrupt();
3635
}

src/main/java/io/concurrency/chapter11/exam04/SupplyAsyncExample.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
import java.util.concurrent.CompletableFuture;
66

77
public class SupplyAsyncExample {
8-
98
public static void main(String[] args) {
109

1110
MyService myService = new MyService();
12-
CompletableFuture.supplyAsync(() -> {
1311

14-
List<Integer> list = myService.getData();
15-
list.stream().forEach(System.out::println);
16-
return list;
12+
List<Integer> result = CompletableFuture.supplyAsync(() -> {
1713

18-
}).join();
14+
System.out.println(Thread.currentThread().getName() + " 가 비동기 작업을 시작 합니다.");
15+
return myService.getData();
1916

20-
System.out.println("메인 작업 종료");
17+
}).join();
2118

19+
result.stream().forEach(System.out::println);
2220
}
2321

2422
static class MyService {

0 commit comments

Comments
 (0)