Skip to content

Commit 7ce42b3

Browse files
committed
lecture
1 parent 998eec9 commit 7ce42b3

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/main/java/io/concurrency/chapter11/exam03/CompletableFutureExample.java

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

1010
CompletableFuture<Object> handle = CompletableFuture.supplyAsync(() -> 2)
1111
.thenApplyAsync(result -> result + 3)
12+
// .thenApplyAsync(result -> {throw new RuntimeException("error");})
1213
.handle((result, exception) -> {
1314
if (exception != null) {
1415
System.out.println("예외 발생: " + exception.getMessage());

src/main/java/io/concurrency/chapter11/exam03/CompletableTask.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
public class CompletableTask {
99
public static void main(String[] args) {
10-
ExecutorService executorService = Executors.newFixedThreadPool(2);
10+
11+
ExecutorService executorService = Executors.newFixedThreadPool(1);
1112
CompletableFuture<Integer> future = new CompletableFuture<>();
1213

1314
executorService.submit(() -> {
14-
int result = performTask();
15-
future.complete(result + 10); // 결과 조작 하고 즉시 완료 시킴
15+
future.complete(5); // 결과 조작 하고 즉시 완료 시킴
1616
});
1717

1818
try {
@@ -24,8 +24,7 @@ public static void main(String[] args) {
2424

2525
executorService.shutdown();
2626
}
27-
2827
private static int performTask(){
2928
return 5;
3029
}
31-
}
30+
}

src/main/java/io/concurrency/chapter11/exam03/ExecutorServiceExample.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
package chapter11.exam03;
1+
package io.concurrency.chapter11.exam03;
22

3-
import java.util.concurrent.*;
3+
import java.util.concurrent.ExecutionException;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
import java.util.concurrent.Future;
47

58
public class ExecutorServiceExample {
69

Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package io.concurrency.chapter11.exam03;
22

3-
import java.util.concurrent.*;
3+
import java.util.concurrent.ExecutionException;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
import java.util.concurrent.Future;
47

58
public class NonCompletableTask {
69
public static void main(String[] args) {
7-
ExecutorService executorService = Executors.newFixedThreadPool(2);
810

9-
Callable<Integer> task = () -> {
10-
int result = performTask();
11-
return result; // 결과 리턴 후 완료 됨
12-
};
13-
14-
Future<Integer> future = executorService.submit(task);
11+
ExecutorService executorService = Executors.newFixedThreadPool(1);
12+
Future<Integer> future = executorService.submit(() -> 5);
1513

1614
try {
1715
int result = future.get() + 10;
@@ -22,7 +20,4 @@ public static void main(String[] args) {
2220

2321
executorService.shutdown();
2422
}
25-
private static int performTask(){
26-
return 5;
27-
}
2823
}

0 commit comments

Comments
 (0)