I am playing around with Threads. I understand that, we can create threads by two methods 1. by Extending Thread class 2. Implementing Runnable. But, I just want to know, when to which method? I tried to find out in some books, I am referring and JLS also... But, Could not get any clear idea about about choosing the right method.. Can anyone plz exaplain... thanks
Joined: Jul 03, 2001
It is easier extending Thread than implementing Runnable and then creating a new Thread. Thus use the first method whenever possible. That is whenever your class is already extending of another you can't go for the first method.
SCJP2. Please Indent your code using UBB Code
Joined: Jun 05, 2002
Hi Murthy, There is only one way to create thread. That is by creating a Thread object ( or its subclass ). Even if you use a Runnable object you still need a Thread object. In this case you delegate what should done in Thread's run() method to the run() method of that Runnable object. This achieves some flexibility ( A thread's executing code doesn't have to be inside a Thread's object but can be anywhere else! )
Joined: Mar 22, 2002
What other people think. [ July 01, 2002: Message edited by: Anthony Villanueva ]