Skip to content

Commit 0cca26f

Browse files
committed
CompletableFuture example
1 parent 6903d14 commit 0cca26f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.test.multithreading;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
import java.util.concurrent.ExecutionException;
5+
6+
public class CompletableFutureExample {
7+
/**
8+
* https://javasampleapproach.com/java/java-8/java-8-completablefuture-
9+
* handle-exception
10+
*
11+
* @param args
12+
* @throws InterruptedException
13+
* @throws ExecutionException
14+
*/
15+
public static void main(String[] args) throws InterruptedException,
16+
ExecutionException {
17+
CompletableFutureExample obj = new CompletableFutureExample();
18+
obj.createCompletableFuture();
19+
}
20+
21+
public void createCompletableFuture() throws InterruptedException,
22+
ExecutionException {
23+
CompletableFuture.runAsync(new Task()).get();
24+
}
25+
}
26+
27+
class Task implements Runnable {
28+
29+
@Override
30+
public void run() {
31+
System.out.println("Hello Task");
32+
33+
}
34+
35+
}

0 commit comments

Comments
 (0)