aspose file tools*
The moose likes Threads and Synchronization and the fly likes Diff between Thread and Runnable Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Diff between Thread and Runnable Interface" Watch "Diff between Thread and Runnable Interface" New topic
Author

Diff between Thread and Runnable Interface

bala subramanian
Greenhorn

Joined: Dec 17, 2001
Posts: 13
Hi all,
I had a few doubts which is summarised below :
(A) Thread Vs Runnable Interface -- tell me with one scenario with eg

(B) Thread Vs Process
Can any one of you clarify the doubts with the examples,if possible
Rgrds,
Bala
Prem Chand
Greenhorn

Joined: Nov 13, 2002
Posts: 3
As u Know Java doesnot support multiple inheritance. It support multiple inheritance only thru interfaces.
When u work with applets u know u have to extend Applet class.
ie. public class myapplet extends Applet{}
In the same program if u want to do threading also it is not possible. So in that case instead of extending Thread we have to implement Runnable interface.
ie. public class myapplet extends Applet implement Runnable{}
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Dough Lea gave in Concurrent Programming in Java two other reasons for using Runnable instead of extending Thread:
a) to separate the task to execute (the code within run) from the "machinery" used to executed it (the Thread object itself)
b) to avoid possible interferences between the locks used by the code within run and the locks used by the Thread class itself.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff between Thread and Runnable Interface