File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
javaCodeTest/src/test/java/com/test/core/juc Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 22
33import org .junit .jupiter .api .Test ;
44
5+ import java .util .concurrent .CompletableFuture ;
56import java .util .concurrent .ConcurrentHashMap ;
67
78/**
@@ -46,6 +47,7 @@ void testDeadLock() {
4647
4748 System .out .println (8899 );
4849
50+
4951 }
5052
5153
You can’t perform that action at this time.
0 commit comments