Skip to content

Commit bbf38a4

Browse files
committed
🚑 🏗️ ⏪
1 parent bf72a07 commit bbf38a4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.test.core.juc;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.concurrent.CompletableFuture;
6+
import java.util.concurrent.ExecutionException;
7+
8+
/**
9+
* @author shuxuecode
10+
* @date 2025/1/10
11+
*/
12+
public class CompletableFutureTest {
13+
14+
15+
@Test
16+
void t1() {
17+
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
18+
19+
if (1==1) {
20+
throw new RuntimeException("123");
21+
}
22+
return "hello world";
23+
});
24+
25+
String s = null;
26+
try {
27+
s = future.get();
28+
} catch (InterruptedException e) {
29+
throw new RuntimeException(e);
30+
} catch (ExecutionException e) {
31+
throw new RuntimeException(e);
32+
}
33+
34+
System.out.println(s);
35+
}
36+
37+
}

javaCodeTest/src/test/java/com/test/core/juc/CurrentHashMapTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import java.util.concurrent.CompletableFuture;
56
import java.util.concurrent.ConcurrentHashMap;
67

78
/**
@@ -46,6 +47,7 @@ void testDeadLock() {
4647

4748
System.out.println(8899);
4849

50+
4951
}
5052

5153

0 commit comments

Comments
 (0)