Skip to content
Ameen Abozaid
Planned lessonMID-003-L02

Threads and their lifecycle

  • Lesson 2 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

create threads and read their states.

Planned topics

  • Thread runs a Runnable; call start(), never run() directly.
  • States: NEW, RUNNABLE, BLOCKED (waiting for a monitor), WAITING and TIMED_WAITING (wait, join, sleep), TERMINATED.
  • join() waits for a thread to finish; interrupt() requests it to stop, and blocking calls throw InterruptedException.
  • Handle interruption: restore the flag or exit; never swallow it.
  • Raw threads are rarely created in services; executors manage them.
Draft outline details

Demonstration

java
Thread t = new Thread(() -> importPrices("acme"));
t.start();
t.join();

Check your understanding

What does calling run() instead of start() do?

Show answer

Runs on the calling thread; no new thread.

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.