Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Thread States and Lifecycle in Java

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.02k
    Comment on it

    Thread Lifecycle: Want to start the multithreaded programming? Before starting you need to know what is Thread and what is the life cycle of the Thread. Thread having different states and life cycle methods. To know about the thread you can Visit my last post Java Thread Example. Here we will talk about the life-cycle of the Thread.

    Following are the states in the life cycle of the Threads :

    1. New: When we initialize the new thread using new operator, new thread is created and state is called New Thread. In this state thread is not active or running.
    2. Runnable: At the time when we call Thread.start() method, state of thread object changed to Runnable and it's now on OS that it when or how it will get CPU to run. In this state the control is given to Thread scheduler to finish its execution.
    3. Running: Now when scheduler run it then state is changed to Running. Thread scheduler picks one of the thread from runnable thread pool and change it's state to Running and thread getting executed.
    4. Blocked/Waiting: When the thread is waiting for another thread to complete or free resource or any user input then the thread is come to waiting state. So once the thread wait state is over, its again comes to Runnable state.
    5. Dead / Terminated: Once the thread finished executing, its state is changed to Dead. As soon as the run() method exits the thread is become dead or its terminated and no longer alive.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: