shutdown and awaitTermination which first call have any difference?

前端 未结 9 1209
渐次进展
渐次进展 2020-12-12 14:44

What is the difference between

ExecutorService eService = Executors.newFixedThreadPool(2);
eService.execute(new TestThread6());
eService.execute(new TestThre         


        
9条回答
  •  心在旅途
    2020-12-12 14:58

    the best implementation:

    executor.shutdown();
        try {
             if (!executor.awaitTermination(3500, TimeUnit.MILLISECONDS)) {
                executor.shutdownNow();
             }                  
        } catch (InterruptedException e) {              
            executor.shutdownNow();
        }
    

提交回复
热议问题