Wednesday, February 25, 2009

example code create thread implement runnable interface



package thread;

class MyThread implements Runnable
{
public void run()
{
for(int i=0; i<=2 ;i++)
System.out.println("child thread");
}

}
public class ThreadDemo2
{
public static void main(String a[])
{
MyThread r=new MyThread();
Thread t=new Thread(r); // Target Runnable
for(int i=0 ; i<=2 ; i++)
{
System.out.println("main thread");
}

}
}

output:
main thread
child thread
main thread
child thread



0 comments:

Post a Comment