Wednesday, November 5, 2008

A sample code of "Thread implements Runnable"

package com.test;

/**
*
* @author seetharam
*/

public class TestThread implements Runnable{

Thread myThread;

public TestThread()
{
System.out.println("in init() -- starting thread.");
myThread= new Thread(this);
myThread.start();
}


public void run()
{
int i=0;
for(;;)
{

System.out.println("At " + i + " and counting!");
try {myThread.sleep(1000);
i++;
}
catch (InterruptedException e ) {}

}
}
public static void main(String a[]){
TestThread obj=new TestThread();

}
}

No comments: