Runnable lnterface

 Runnable Interface


// Create Threads using Runnable Interface 


class NewThd implements Runnable

{

Thread t;

NewThd()

{

t = new Thread(this, "CT");

System.out.println(t);

}

public void run()

{

try

{

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

{

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

Thread.sleep(1000);

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}


class Demo_RunnableIntf

{

public static void main(String as[])

{

NewThd NT = new NewThd();

NT.t.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