This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
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: 1388
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
Rancher

Joined: Mar 22, 2005
Posts: 42955
    
  73
This may help: http://faq.javaranch.com/java/ExtendingThreadVsImplementingRunnable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extends Thread Vs implements Runnable