Friday, 24 May 2013

Threads Life Cycle

Steps in Threds Life cycle.

1)Create Thread – Thread can be created by extending a Thread Class Or Implementing Runnable Interface 

2)New State – When  Thread is crated it is in new state.

3)Runnable – When    method of thread is called means thread is now in runnable state.

4)Running – When thread call it's run method() it is in runing state.

5)Dead – When thred finished it's run method then it enter into dead state, dead thred never start again.

6)Block States – Thread can be in block state by calling wait(), sleep() method.




class Demoimplements Runnable 

{
  String str;
  public Demo(String s) 
{ str = s; 
}
  public void run()
 {
    while (true)
 {
      System.out.print(str);
      System.out.println();


    }
  } 
}




class TestDemo
 {

  public static void main(String[] args) 

{
    Jabber j = new Demo("Computer Dept");
    Jabber k = new Jabber("Computer Science 101");
    Thread t = new Thread(j);
    Thread u = new Thread(k);
    t.start();
    u.start();

}.



Aryantech India pune

No comments:

Post a Comment