Thead life cycle in java?


  • When you create and stop the thread then thread will be entered into ready to run sate and will wait for the CPU time.
  •    When thread get the CPU time then run method will be called and will be moves to running state only thread which is in the running state will use the CPU time.
  •     When you  call the sleep method  on the running  thread then thread will be moved to sleep state and when specified time is over then thread will be return  ready to run state.
  •     When you call wait method on running thread then thread will be moves to wait state waiting thread can be moved to ready to run sate By calling notify() or notifyAll() method . when you call notify() then thread which is entered to wait state 1st will be moved to ready to run state 1st . (this will happened based on LRE algorithm – least recently entered method  )
  •     When you call notifyAll() then all the thread will be moved to ready to run state One by one  based on LRE algorithm .
  •     When running thread is requesting a resource which is not available then thread will be moved to block state. Again block thread will be return to ready to run state when that requested resource is available .this scenario some time leads to deadlock.
  •     When run() method execution is completed then thread task is completed ,then thread will go to dead state. Once thread is in dead sate, there is no chance of getting it back.