Junior
In what states can a stream be?
sobes.tech AI
Answer from AI
A thread in Java can be in the following main states, defined by the enumeration Thread.State:
- NEW: The thread has been created but not yet started.
- RUNNABLE: The thread is executing in the JVM but may be waiting for CPU time allocated by the operating system. Includes Running and Ready states.
- BLOCKED: The thread is blocked and waiting for a monitor lock to enter a synchronized block or method, or reenter it.
- WAITING: The thread is waiting for another thread to perform a specific action without a time limit. For example, by calling
Object.wait(),Thread.join()without a timeout, orLockSupport.park(). - TIMED_WAITING: The thread is waiting for another thread to perform a specific action within a specified period. For example, by calling
Thread.sleep(),Object.wait()with a timeout,Thread.join()with a timeout,LockSupport.parkNanos(), orLockSupport.parkUntil(). - TERMINATED: The thread has finished execution.
The thread states can be obtained using the method thread.getState().