-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFutureExceptionMain.java
More file actions
40 lines (33 loc) · 1.11 KB
/
Copy pathFutureExceptionMain.java
File metadata and controls
40 lines (33 loc) · 1.11 KB
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
33
34
35
36
37
38
39
40
package thread.executor.future;
import util.MyLogger;
import util.ThreadUtils;
import java.util.concurrent.*;
import static util.MyLogger.log;
import static util.ThreadUtils.sleep;
public class FutureExceptionMain {
public static void main(String[] args) {
ExecutorService es = Executors.newFixedThreadPool(1);
log("작업 전달");
Future<Integer> future = es.submit(new ExCallble());
sleep(1000);
try {
log("future.get() 호 시도, future.state() : ");
Integer result = future.get();
log("result value : " + result );
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
log("e : " + e);
Throwable cause = e.getCause();
log("cause : " + cause);
e.printStackTrace();
}
}
static class ExCallble implements Callable<Integer> {
@Override
public Integer call() throws Exception {
log("Callable 실행, 예외 발생");
throw new IllegalStateException("ex!");
}
}
}