JAVA : Life Cycle of Thread in Multithreading By Java2021 - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Tuesday, July 7, 2020

JAVA : Life Cycle of Thread in Multithreading By Java2021

This is theory part of life cycle of thread ( Multithreading)

Thread have 4 States 

  • New Thread/State
  • Runnable State
  • Non-Runnable State
  • Dead/Terminate State
Explain one by one what happen in this states : 
New thread State : 
  • A thread is in this state when the instantiation of a thread object creates a new thread but does not start it running
  • A thread starts life in the ready-to-run state
  • You can call only the start() or stop() when the thread is in this state.
  • Calling any methods besides start() or stop() causes an illegalThreadStateException.(run time exception)
Runnable State
  • When the start() method is invoked on a new thread() it get to the runnable state or running state by calling the run() methods
  • A runnable thread may actually be running or may be awaiting it turn to run
Not Runnable State :  Threads are non runnable state if this four condition occur-
  • A thread becomes not runnable when one of the following four events occurs
  • When sleep method invoked and it sleeps  for a specified amount of time
  • When suspend() method is invoked
  • When the wait() method is invoked
  • The thread is blocking on I/O and waits for its completion
Note : switching from not runnable state to runnable state
  • if a thread has been put to sleep,then the specified number of millisecond must elapse(or it must be interrupted)
  • if thread has been suspended() then its resume() method must be invoked.
  • if a thread is waiting on a condition variable,whatever object owns the variable must relinquish it by calling either notify() or notifyAll().
  • if a thread is blocked on I/O,then the I/O must complete.
Dead/Terminated State :  
  • A thread enters this state when the run() method has finished executing or when the stop() method is invoked.
  • Once in this state,the thread cannot ever run again.
Click to Next :

Sorting and Searching Programs

Start with your Choice

-Important Programs for Freshers

Learn Pattern Programs 

Click to learn Array Programs

Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

No comments:

Pages