A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Elasticsearch in Action
this week in the
Threads and Synchronization
implements Runnable and extending Thread
Joined: Aug 06, 2012
Aug 06, 2012 10:03:52
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.
Joined: Jun 02, 2011
Aug 06, 2012 10:17:46
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
Aug 06, 2012 12:10:13
No. *Always* implement Runnable. Your class is not a Thread, so it shouldn't extend it.
I agree. Here's the link:
subject: implements Runnable and extending Thread
extend or implement?
Implementing Runnable or Extending Thread class
How can MultiThreading is implemented in Servlets
Why Thread class is present
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015