Skip to content
Ameen Abozaid
Planned lessonMID-003-L05

Shutdown and failure handling

  • Lesson 5 of 7
  • Mid-level
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), then shutdownNow().
  • Non-daemon pool threads keep the JVM alive if you never shut down.
  • Tasks given to execute that throw print to the thread's uncaught handler; with submit the exception hides inside the Future until get().
  • Always log or collect failures.
Draft outline details

Demonstration

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.