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?

3 answers

  • answered 2018-04-17 06:05 Torben

    https://docs.oracle.com/javase/9/docs/api/java/lang/Thread.State.html

    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.

  • answered 2018-04-17 06:06 孙兴斌

    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.

  • answered 2018-04-17 06:14 nits.kk

    As per Java docs these are the states defined

    1. NEW : when an object of thread (lets call it T) is created.
    2. Runnable : when T is started and it participates in consuming the CPU cycles. It is the running state.
    3. 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 )
    4. 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.
    5. TIMED_WAITING : Similar to WAITING state but for a defined time period. Once time period is over it gets out of this state
    6. TERMINATED : the thread execution is over (end of run method).

    https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.State.html