This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Java has only 1 way to create a thread. With the thread class (or a child of it). However it can be used in combination with the runnable interface.
It's just an abstraction of the code to be executed. It's generally discouraged to extend the Thread class. The Thread class has a lot of overhead
and the Runnable interface doesn't.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
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.
I'd look at it this way. What is a Thread? It represents a process running on the machine, that can execute some actions. What is a Runnable? It represents an action to execute. These are really two completely different concepts - so general object-oriented principles suggest that using two different objects is likely to be preferable.