1. 程式人生 > >優雅的關閉執行緒池

優雅的關閉執行緒池

   @PreDestroy
         public void destory() {
                   try {
                            scheduledExecutorService.shutdown();

                            if (!scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS)) {
                                     scheduledExecutorService.shutdownNow();
                            }
                   } catch (InterruptedException e) {
                            scheduledExecutorService.shutdownNow();
                   }
         }