Thread Class

 Thread Class 


// Create Threads using Thread class 


class NewThd extends Thread

{

NewThd()

{

super("CT");

System.out.println(this);

}

public void run()

{

try

{

for(int i=0;i<5;i++)

{

System.out.println(this.getName()+" "+i);

Thread.sleep(1000);

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}


class Demo_ThdClass

{

public static void main(String as[])

{

NewThd NT = new NewThd();

NT.start();

Thread T = Thread.currentThread();

T.setName("MT");

try

{

for(int i=0;i<5;i++)

{

System.out.println(T.getName()+" "+i);

Thread.sleep(1000);

}

}

catch(Exception e)

{

System.out.println(e);

}                    

}

}

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu