File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
03concurrency/0301/src/main/java/java0/conc0302/threadpool Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package java0 .conc0302 .threadpool ;
2+
3+ import java .util .concurrent .ExecutorService ;
4+ import java .util .concurrent .Executors ;
5+ import java .util .concurrent .Future ;
6+
7+ public class ExceptionDemo {
8+
9+ public static void main (String [] args ){
10+ ExecutorService executorService = Executors .newFixedThreadPool (1 );
11+
12+ try {
13+ Future <Double > future = executorService .submit (() ->{
14+ int a = 1 ;
15+ return 10.0 /(a -1 );
16+ });
17+
18+ double b = future .get ();
19+ System .out .println (b );
20+
21+ } catch (Exception ex ){
22+ System .out .println ("catch execute" );
23+ ex .printStackTrace ();
24+ }
25+
26+ try {
27+ executorService .execute (() ->{
28+ int a = 1 ;
29+ float b = 10 /(a -1 );
30+ });
31+ } catch (Exception ex ){
32+ System .out .println ("catch execute" );
33+ ex .printStackTrace ();
34+ }
35+
36+ executorService .shutdown ();
37+ System .out .println ("Main Thread End!" );
38+ }
39+
40+ }
You can’t perform that action at this time.
0 commit comments