Card 08/ 08
Recap: Threads and What They Cost
start against run, interleaving, one-way states, virtual threads and daemons, with where each was.
Threads come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
start() creates a thread; run() is an ordinary method call | Thread.run() vs Thread.start(): Why Calling run() Starts Nothing |
| Each thread's own order holds; the interleaving between threads does not | Thread Example: Two Threads Printing at Once |
| A thread runs once and cannot be restarted | Thread States: NEW, RUNNABLE, BLOCKED, WAITING and TERMINATED |
| A virtual thread is scheduled by the virtual machine and costs almost nothing | Platform Threads vs Virtual Threads |
| The process exits when the last non-daemon thread finishes | Daemon Threads: Why a Java Program Does Not Exit |
A thread buys overlap and spends ordering. Everything else in this subject is about the consequences of that trade, and none of it shows in code that runs on one thread.
← → move through sections and cards