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:
- NEW — the thread has been created but not started.
- RUNNABLE — the thread is ready to run and may be executing.
- BLOCKED — the thread is blocked, waiting for a monitor (e.g., during synchronization).
- WAITING — the thread is waiting for notification without a timeout.
- TIMED_WAITING — the thread is waiting with a timeout (e.g., sleep, wait with timeout).
- TERMINATED — the thread has finished execution.
In total, a thread can have 6 main states.