-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheadPoolTest.java
More file actions
49 lines (42 loc) · 1.51 KB
/
Copy pathTheadPoolTest.java
File metadata and controls
49 lines (42 loc) · 1.51 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
41
42
43
44
45
46
47
48
49
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class TheadPoolTest {
public static void main(String[] args) {
// ExecutorService service = Executors.newFixedThreadPool(1);
// Runnable r = () -> System.out.println(1 / 0);
// service.submit(r);
// service.shutdown();
ExecutorService executorService = Executors.newCachedThreadPool();
Thread thread = new Thread(() -> {
int i=1/0;
System.out.println("test");
});
Runnable runnable = new Runnable() {
@Override
public void run() {
int i=1/0;
System.out.println("run0");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("run1");
}
};
//executorService.execute(thread);
//executorService.execute(runnable);
executorService.submit(thread);
Future<?> future = executorService.submit(runnable);
System.out.println("future.get() start");
try {
System.out.println(future.get());
} catch (InterruptedException | ExecutionException e) {
System.out.println("exception");
}
System.out.println("future.get() end");
executorService.shutdown();
}
}