Sobes.tech
Junior — Middle

How many states can a thread of execution in a program have?

sobes.tech AI

Answer from AI

In Java, a thread can be in one of the following states:

  1. NEW — the thread has been created but not started.
  2. RUNNABLE — the thread is ready to run and may be executing.
  3. BLOCKED — the thread is blocked, waiting for a monitor (e.g., during synchronization).
  4. WAITING — the thread is waiting for notification without a timeout.
  5. TIMED_WAITING — the thread is waiting with a timeout (e.g., sleep, wait with timeout).
  6. TERMINATED — the thread has finished execution.

In total, a thread can have 6 main states.