Junior — Middle
Can you list and describe the main states a thread can be in?
sobes.tech AI
Answer from AI
Main thread states in Java:
- New — the thread is created but the
start()method has not yet been called. - Runnable — the thread is ready to run and waiting for the scheduler.
- Running — the thread is executing (this is an implicit state as JVM manages switching).
- Blocked — the thread is waiting to acquire a monitor (e.g., entering a synchronized block).
- Waiting — the thread is waiting for a notification (
wait(),join()without timeout). - Timed Waiting — the thread is waiting for a specified period (
sleep(),join()with timeout). - Terminated — the thread has finished execution.
These states help manage multithreading and synchronization in Java.