Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Diff between Thread and Runnable Interface

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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{}
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's feeding time! Give me the food you were going to give to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic