Skip to content

Instantly share code, notes, and snippets.

@Sonique
Created April 24, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sonique/1c3491f54cb8ce513c546773cb68f626 to your computer and use it in GitHub Desktop.
Save Sonique/1c3491f54cb8ce513c546773cb68f626 to your computer and use it in GitHub Desktop.
Java Executor proper shutdown
try {
System.out.println("attempt to shutdown executor");
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
System.err.println("tasks interrupted");
}
finally {
if (!executor.isTerminated()) {
System.err.println("cancel non-finished tasks");
}
executor.shutdownNow();
System.out.println("shutdown finished");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment