SteelReed

Search

Search posts, questions…

ConcurrencyQuestion 2 / 19

Junior

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.

startwaits for synchronizedmonitorgets the monitorwait, join, parksleep, timed waitrun endsNEWRUNNABLEBLOCKEDWAITINGTIMED_WAITINGTERMINATED

3 points to say:

  1. 6 states, no separate "RUNNING": RUNNABLE covers running, ready to run, and waiting on socket I/O.
  2. start() creates a new OS thread and calls run() on it; calling run() directly just runs on the current thread.
  3. sleep keeps the lock, wait releases it; pass a Runnable/Callable to an executor instead of extends 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.