forked from davidjava1991/java17CompleteCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.java
More file actions
27 lines (24 loc) · 766 Bytes
/
Copy pathExample2.java
File metadata and controls
27 lines (24 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.david.class165;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
public class Example2 {
public static void main(String[] args) {
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
Future<String> op1 = executor.submit(() -> {
Thread.sleep(500);
return "thread 1 done";
});
Future<String> op2 = executor.submit(() -> {
Thread.sleep(500);
return "thread 2 done";
});
try {
System.out.println(op1.get());
System.out.println(op2.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}