Threads and their lifecycle
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
Threadruns aRunnable; callstart(), neverrun()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 throwInterruptedException.- Handle interruption: restore the flag or exit; never swallow it.
- Raw threads are rarely created in services; executors manage them.
Draft outline details
Demonstration
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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.