A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Murach's Java Servlets and JSP
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.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
subject: implements Runnable and extending Thread
Implementing Runnable or Extending Thread class
Why Thread class is present
extend or implement?
How can MultiThreading is implemented in Servlets
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014