Rohit Gupta
What is a Thread-Lifecycle in Java?
By Rohit Gupta in Java on Sep 10 2019
  • Laxmidhar Sahoo
    Jan, 2020 8

    Look for some more

    Waiting
    A thread can be put in waiting state for various reasons e.g. calling it’s wait() method. Usually program put a thread in WAIT state because something else needs to be done prior to what current thread is doing.

    Read More: Working With wait(), notify() and notifyAll() in Java?

    Once the thread wait state is over or it is, it’s state is changed to RUNNABLE and it’s moved back to thread pool.

    Timed Waiting
    A RUNNABLE thread can transition to the TIMED WAITING state if it provides an optional wait interval when it’s waiting for another thread to perform a task. You can put a java thread in TIMED WAITING state by calling it’s sleep(long millis) method or wait(long millis) method.

    Such a thread returns to the RUNNABLE state when it’s notified by another thread or when the timed interval expires—whichever comes first.

    Timed waiting threads and waiting threads cannot use a processor, even if one is available.

    • 0
  • Vijay Kumari
    Sep, 2019 16

    1) New

    A new state is the first state of the thread. The thread is in new state if we create an object of the Thread class but before the invocation of start() method.

    2) Runnable

    After a new thread starts, the thread is in the second state after the invocation of start() method, but the scheduler has not selected it to be in the running thread.

    3) Running

    The third state is running. The thread is in running state if the thread scheduler has selected it.

    4) Non-Runnable (Blocked)

    The fourth state is non-runnable(blocked). This is the state when the thread is alive but is currently not eligible to run.

    5) Terminated

    The last state of a thread is terminated. A thread is in the terminated state when its run() method exits.

    For a detailed tutorial on Java MultiThreading, visit
    https://www.c-sharpcorner.com/article/a-complete-multithreading-tutorial-in-java/

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS