Pages

Ads 468x60px

Monday 17 December 2012

Life cycle of thread

 WAJP demonstrating the life cycle of a thread.
Program:
                                   Download link for life cycle of thread
class MyThreadDemo extends Thread
{
 public MyThreadDemo()
     {
    System.out.println(this.getName()+"is newly born");
   }
 public void run()
   {  
  try
   { 
    int i=0;
      while(i<3)
     System.out.println(this.getName()+"Thread is in running state:");
   i++;
   System.out.println("Thread going to sleeping static"); 
  Thraed.sleep(2000);
   }
  System.out.println("Thread completed running state & Thread completed");
 }
 catch(InterruptedException ie)
 ie.print stackTrace();
  {
   }
  }
 }
class StateDemo
 {
 public static void main(String[] args)
  {
 System.out.println("Inside main Thread"); 
   MyThreadDemo obj=new MyThreadDemo();
     obj.setName("T1");
     obj.start(); 
   }
}

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text