Created
April 24, 2017 10:02
-
-
Save Sonique/1c3491f54cb8ce513c546773cb68f626 to your computer and use it in GitHub Desktop.
Java Executor proper shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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