-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallableMainV1.java
More file actions
32 lines (24 loc) · 852 Bytes
/
Copy pathCallableMainV1.java
File metadata and controls
32 lines (24 loc) · 852 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
32
package thread.executor.future;
import util.MyLogger;
import util.ThreadUtils;
import java.util.Random;
import java.util.concurrent.*;
public class CallableMainV1 {
public static void main(String[] args) throws ExecutionException, InterruptedException {
ExecutorService es = Executors.newFixedThreadPool(1);
Future<Integer> future = es.submit(new MyCallable());
Integer result = future.get();
MyLogger.log("resule = " + result);
es.shutdownNow();
}
static class MyCallable implements Callable<Integer> {
@Override
public Integer call() throws Exception {
MyLogger.log("Callable 시작");
ThreadUtils.sleep(2000);
int value = new Random().nextInt(10);
MyLogger.log("Callable 종료");
return value;
}
}
}