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

implements Runnable and extending Thread

Mohanasundaram Govindarajan

Joined: Aug 06, 2012
Posts: 5

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

Joined: Sep 20, 2010
Posts: 4600

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 agree. Here's the link:
subject: implements Runnable and extending Thread
jQuery in Action, 3rd edition