File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes implements Runnable and extending Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "implements Runnable and extending Thread" Watch "implements Runnable and extending Thread" New topic
Author

implements Runnable and extending Thread

Mohanasundaram Govindarajan
Greenhorn

Joined: Aug 06, 2012
Posts: 4
Hi,

Which one is the best to create the Thread. i.e Implements Runnable or extends Thread.

I know that if we create thread by extending Thread class, multiple inheritance is not possible. So we can create thread by implementing Runnable to overcome this.

I want to Know if my class does not have super class , then which one is the best,Please justify.
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95

Hi Mohan,

First of all welcome to Ranch!!!
If you have to inherit a class already then I recommend "implements Runnable" because as you know a class cannot inherit multiple classes.
If you don't have to inherit any class then you can use either
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

No. *Always* implement Runnable. Your class is not a Thread, so it shouldn't extend it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implements Runnable and extending Thread