File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Thread class or Runnable interface ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread class or Runnable interface ??" Watch "Thread class or Runnable interface ??" New topic
Author

Thread class or Runnable interface ??

mustang india
Ranch Hand

Joined: Feb 05, 2002
Posts: 60
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

Joined: Aug 09, 2001
Posts: 202
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

Joined: May 10, 2001
Posts: 3244
Basically, if your class is a subclass of another class you can't extend thread so you'd have to use Runnable.


Dave
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1158

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.
 
 
subject: Thread class or Runnable interface ??
 
Threads others viewed
why does java have a thread class and a Runnable interface??
run()
Diff between Thread and Runnable
Maybe mistake in the study guide
Threads Queries
IntelliJ Java IDE