Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread class or Runnable interface ??  RSS feed

 
mustang india
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can one decide whether to use Thread class or Runnable interface.
I know one scenario where if my class already extends another class, it has no choice but to implement the Runnable interface. Are there any other scenarios ?
Regards,
Mustang.
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose u want u'r class to act as a Thread i.e to be instantiated from other classes u extend u'r class from java.lang.Thread.
eg).performing a certain calculation.
If u r using threads within u'r class to do a certain job u implement runnable.
eg). using swing & displaying some animations.
This is what I know.
Happy middling with java.
Netharam.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, if your class is a subclass of another class you can't extend thread so you'd have to use Runnable.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its your choice. Typically one extends a class to add to its functionality though. Since their is no double inheritance, you can simply use Runnable, but it does not matter one bit.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!