Always shut down an ExecutorService

The ExecutorService interface is among the most commonly used items in the java.util.concurrent package. When finished using an ExecutorService, you need to shut it down explicitly. From its javadoc:

"An unused ExecutorService should be shut down to allow reclamation of its resources."

Calling shutdown initiates a gradual and orderly shutdown. Submitted tasks are still executed, but no new tasks will be accepted. If you then want to wait until shutdown has completed, call awaitTermination.

Alternatively, call shutdownNow to terminate in a more aggressive manner.

Would you use this technique?
Yes   No   Undecided   
© 2014 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on September 21, 2013.
Over 2,000,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -