Tuesday, June 9, 2009

Thread

class MyThread extends Thread{

public static void main(String ar[]){

MyThread obj=new MyThread();
obj.create();

System.out.println("This is the main Thread");
}

public void create(){

Thread obj1=new Thread(this);

obj1.start();
}

public void run(){

while(true){
try{
System.out.println("This is the child Thread ");
Thread.sleep(500);
}
catch(InterruptedException ex)
{
System.out.println("Error : "+ex);
}
}
}
}

No comments:

Post a Comment