wood burning stoves
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: 5
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: 3989
    
  18

No. *Always* implement Runnable. Your class is not a Thread, so it shouldn't extend it.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: implements Runnable and extending Thread
 
It's not a secret anymore!