aspose file tools*
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: 1378
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: 42264
    
  64
This may help: http://faq.javaranch.com/java/ExtendingThreadVsImplementingRunnable


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extends Thread Vs implements Runnable