As you can see Thread implements Runnable. You are going to need to override run(), and you use run() when you implement Runnable, so no difference there. You can even call the non-static methods of Thread if you need to inside your Runnable, but you need to call Thread.currentThread(), so you aren't losing any functionality by not using the Runnalbe interface instead.
extend Thread and you are stuck, you can't extend another class if you need it. So just implement Runnable. Starting the thread is also slightly different.
[ August 16, 2006: Message edited by: Rusty Shackleford ] [ August 16, 2006: Message edited by: Rusty Shackleford ]
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Joined: Jan 29, 2003
Most of us figure Thread implementing Runnable was a mistake and extending Thread is (almost?) always a bad idea. We tend to use Runnable, TimerTask, FutureTask and the like.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Oct 04, 2006
I have few comments over this point:
1) Interface Runnable have only 1 method which you mandatory to implement.
2) If you need other methods like suspend() resume() sleep() join() yield() and stop() then
go for extending class Thread
3) Extending the Thread class will make your class unable to extend other classes, because of the single inheritence feature in JAVA.
4) If you want to execute run() method for multiple no of times then its better to you Runnable.
5) Thread Class actually implements Runnable interface internally.
Joined: Sep 16, 2009
Thread class & runnable interface are the same.the difference is just that of a class and an interface and usage depends on design decision.
Objects of class implementing runnable don't act as threads. they have to b given to Thread objects which actually spawn a new thread.
for general usage we put the required code block in a Runnable implementing class. Now this becomes service which needs to b executed. its object is then given to actual Thread object to create a thread and run this service.
Extend thread only when you want to add functionality to Thread class