File tree Expand file tree Collapse file tree 1 file changed +32
-17
lines changed
java/javase/javase-juc/src/main/java/cn/edu/ntu/javase/thread/pool Expand file tree Collapse file tree 1 file changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -65,23 +65,6 @@ public static void main(String[] args) {
6565 log .info ("main method end ..." );
6666 }
6767
68- @ SneakyThrows
69- @ Test
70- public void checkAsync () {
71-
72- CompletableFuture <RuntimeException > supplyAsync =
73- CompletableFuture .supplyAsync (
74- () -> {
75- log .info ("thread 2 supply async start ... " );
76- return new RuntimeException ("thread-2" );
77- });
78- Optional .ofNullable (supplyAsync .get ())
79- .ifPresent (
80- x -> {
81- throw x ;
82- });
83- }
84-
8568 @ SneakyThrows
8669 @ Test
8770 public void checkAsyncAllof () {
@@ -120,4 +103,36 @@ public void checkAsync2() {
120103
121104 runAsync .get ();
122105 }
106+
107+ @ SneakyThrows
108+ @ Test
109+ @ Deprecated
110+ public void checkAsync () {
111+
112+ CompletableFuture <RuntimeException > supplyAsync =
113+ CompletableFuture .supplyAsync (
114+ () -> {
115+ log .info ("thread 2 supply async start ... " );
116+ return new RuntimeException ("thread-2" );
117+ });
118+ Optional .ofNullable (supplyAsync .get ())
119+ .ifPresent (
120+ x -> {
121+ throw x ;
122+ });
123+ }
124+
125+ @ SneakyThrows
126+ @ Test
127+ public void checkAsyncJoin () {
128+
129+ CompletableFuture <Void > supplyAsync =
130+ CompletableFuture .runAsync (
131+ () -> {
132+ log .info ("thread 2 supply async start ... " );
133+ throw new RuntimeException ("thread-2" );
134+ });
135+
136+ CompletableFuture .allOf (supplyAsync ).join ();
137+ }
123138}
You can’t perform that action at this time.
0 commit comments