사용자 도구

사이트 도구


java:concurrent:executorservice

문서의 이전 판입니다!


Java ExecutorService

Basic ExecutorService shutdown Pattern

 void shutdownAndAwaitTermination(ExecutorService pool) {
   pool.shutdown(); // Disable new tasks from being submitted
   try {
     // Wait a while for existing tasks to terminate
     if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
       pool.shutdownNow(); // Cancel currently executing tasks
       // Wait a while for tasks to respond to being cancelled
       if (!pool.awaitTermination(60, TimeUnit.SECONDS))
           System.err.println("Pool did not terminate");
     }
   } catch (InterruptedException ie) {
     // (Re-)Cancel if current thread also interrupted
     pool.shutdownNow();
     // Preserve interrupt status
     Thread.currentThread().interrupt();
   }
 }
 
java/concurrent/executorservice.1457268628.txt.gz · 마지막으로 수정됨: 2016/03/06 21:20 저자 kwon37xi