-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvokeAllMain.java
More file actions
31 lines (24 loc) · 998 Bytes
/
Copy pathInvokeAllMain.java
File metadata and controls
31 lines (24 loc) · 998 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
28
29
30
31
package thread.executor;
import util.MyLogger;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import static util.MyLogger.log;
public class InvokeAllMain {
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService es = Executors.newFixedThreadPool(10);
CallableTask task1 = new CallableTask("task1", 1000);
CallableTask task2 = new CallableTask("task2", 2000);
CallableTask task3 = new CallableTask("task3", 3000);
List<CallableTask> list = List.of(task1,task2,task3);
List< Future<Integer>> futures = es.invokeAll(list);
log("완료 되기 전에는 나오면 안되는 Log");
for (Future<Integer> future : futures) {
Integer value = future.get();
log("value = " + value);
}
es.shutdown();
}
}