Shutdown and failure handling
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
stop pools cleanly and not lose failures.
Planned topics
shutdown()stops accepting tasks and lets queued ones finish;shutdownNow()interrupts workers.- Pattern:
shutdown(),awaitTermination(timeout), thenshutdownNow(). - Non-daemon pool threads keep the JVM alive if you never shut down.
- Tasks given to
executethat throw print to the thread's uncaught handler; withsubmitthe exception hides inside theFutureuntilget(). - Always log or collect failures.
Draft outline details
Demonstration
pool.shutdown();
if (!pool.awaitTermination(30, TimeUnit.SECONDS)) pool.shutdownNow();Check your understanding
Why can a failed submit task go unnoticed?
Show answer
The exception is stored in the Future; nobody called get().
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.