Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.     public void shutdownExecutorAndAwaitTermination(ExecutorService pool) {
  2.         System.out.printf("!!!!!!!! Executor has shutdown - no more requests");
  3.         pool.shutdown(); // Disable new tasks from being submitted
  4.         try {
  5.           // Wait a while for existing tasks to terminate
  6.           if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
  7.             pool.shutdownNow(); // Cancel currently executing tasks
  8.             System.out.printf("!!!!!!!! Tasks running after 60 seconds have been cancelled");
  9.             // Wait a while for tasks to respond to being cancelled
  10.             if (!pool.awaitTermination(60, TimeUnit.SECONDS))
  11.                 System.err.println("Pool did not terminate");
  12.           }
  13.         } catch (InterruptedException ie) {
  14.           // (Re-)Cancel if current thread also interrupted
  15.           pool.shutdownNow();
  16.           // Preserve interrupt status
  17.           Thread.currentThread().interrupt();
  18.         }
  19.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement