What states can a Java thread be in? How does start() differ from run()?
Short answer
Thread.State has 6 states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED. Only start() creates a new OS thread; calling run() directly is just a method call on the current thread.
3 points to say:
- 6 states, no separate "RUNNING":
RUNNABLEcovers running, ready to run, and waiting on socket I/O. start()creates a new OS thread and callsrun()on it; callingrun()directly just runs on the current thread.sleepkeeps the lock,waitreleases it; pass aRunnable/Callableto an executor instead ofextends Thread.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.