wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes extend or implement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "extend or implement?" Watch "extend or implement?" New topic
Author

extend or implement?

amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
we can create thread by extending Thread class or implementing Runnable interface...

as far as my knowledge goes implementing is a better option for following 2 reasons:
(1) by implementing i have option of extending another class
(2) by extending the entire Thread class i would have the overhead of all properties of Thread class...which in some cases is not required.

so my question is while creating a thread which is the best and effecient way to create it and why?

help appreciated

cheers
amal
Amit Saini
Ranch Hand

Joined: Oct 20, 2004
Posts: 280
Extending Thread really means that you're creating a more specialized class of Thread - to do more than what Thread does, if you look at it from an OO perspective.
If that is not your goal, implementing is the way to go.
 
 
subject: extend or implement?