join makes the result safe to read
A thread moves through six states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING and TERMINATED. join waits for another thread to finish, sleep pauses the current one, and interrupt politely asks a thread to stop what it's waiting for.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Start three threads that each compute part of a sum (1..300 split into three ranges), join them all, and print the total.
Write a thread that prints "tick" every 20 ms and is stopped after about 70 ms by interrupt; print only how it ended.
Explain it without notes
Name the six thread states and give one action that puts a thread into each.
What does join guarantee besides waiting?
How should code respond to InterruptedException, and why?
Expected output
summer computed 500500
alive after join? false