@@ -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