Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff between Thread and Runnable Interface

 
bala subramanian
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic