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();
}
}
{
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