Skip to content

Commit 6d921f5

Browse files
committed
update
1 parent 49da3e2 commit 6d921f5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
packagejava0.conc0302.threadpool;
2+
3+
importjava.util.concurrent.ExecutorService;
4+
importjava.util.concurrent.Executors;
5+
importjava.util.concurrent.Future;
6+
7+
publicclassExceptionDemo{
8+
9+
publicstaticvoidmain(String[] args){
10+
ExecutorServiceexecutorService = Executors.newFixedThreadPool(1);
11+
12+
try{
13+
Future<Double> future = executorService.submit(() ->{
14+
inta = 1;
15+
return10.0/(a-1);
16+
});
17+
18+
doubleb = future.get();
19+
System.out.println(b);
20+
21+
} catch (Exceptionex){
22+
System.out.println("catch execute");
23+
ex.printStackTrace();
24+
}
25+
26+
try{
27+
executorService.execute(() ->{
28+
inta = 1;
29+
floatb = 10/(a-1);
30+
});
31+
} catch (Exceptionex){
32+
System.out.println("catch execute");
33+
ex.printStackTrace();
34+
}
35+
36+
executorService.shutdown();
37+
System.out.println("Main Thread End!");
38+
}
39+
40+
}

0 commit comments

Comments
(0)