Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void shutdownExecutorAndAwaitTermination(ExecutorService pool) {
- System.out.printf("!!!!!!!! Executor has shutdown - no more requests");
- 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
- System.out.printf("!!!!!!!! Tasks running after 60 seconds have been cancelled");
- // 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement