Thursday, June 01, 2006

Runnable Interface

class MyRunnable implements Runnable
{
public void run()
{
System.out.println("Inside run()");
}
}


Next, create an instance of the class and construct a thread, passing the instance of the class as an argument to the constructor:

MyRunnable mc = new MyRunnable();
Thread t = new Thread(mc);


To start the thread, use the start() method as shown here:
t.start();

0 Comments:

Post a Comment

<< Home