Java Thread: According to sun there are only four stages in thread life cycle
According to sun microsystems thread has only four stages:
1. New 2. Runnable 3. Non-Runnable (Blocked) 4. Terminated
According to them there is no running state.
Why is it so?
What is the state when thread running?
According to the documentation (you read it, didn't you? :)) RUNNABLE means "A thread executing in the Java virtual machine is in this state."
So it seems to be just the choice of words in the enumeration that is confusing you.
Better see the doc:
public static final Thread.State RUNNABLE
Thread state for a runnable thread. A thread in the runnable state is executing in the Java virtual machine but it may be waiting for other resources from the operating system such as processor.
As per Java docs these are the states defined
- NEW : when an object of thread (lets call it T) is created.
- Runnable : when T is started and it participates in consuming the CPU cycles. It is the running state.
- BLOCKED : when T is blocked on a monitor of a lock (T may be blocked to enter a synchronized block or method as some other thread is executing that block or method )
- WAITING : Thread is waiting (will not be picked by thread scheduler to consume CPU cycle). Until it is notified or interrupted it remains in this state.
- TIMED_WAITING : Similar to WAITING state but for a defined time period. Once time period is over it gets out of this state
- TERMINATED : the thread execution is over (end of run method).