This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes extends Thread  Vs  implements Runnable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "extends Thread  Vs  implements Runnable" Watch "extends Thread  Vs  implements Runnable" New topic
Author

extends Thread Vs implements Runnable

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1303
Both are implementing run() method. If i choose Runnable interface, supports multiple interface inheritance. Why do we need Thread class ?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
If you implement Runnable you still have to pass your class to a Thread if you want to start it. Following the 'Favor Composition Over Inheritance' you most likely are always better off implementing Runnable than extending Thread.


JDBCSupport - An easy to use, light-weight JDBC framework -
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35442
    
    9
This may help: http://faq.javaranch.com/java/ExtendingThreadVsImplementingRunnable


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: extends Thread Vs implements Runnable
 
Similar Threads
run method
difference between thread & runnable
Thread/ Runnable
Passing this to a constructor
About Multithreading in java