• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Thread Class and Runnable Interface

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we want to create thread then
we extend Thread class or Implement Runnable interface
Why we have two seperate option to creat a Thread
Is there any special reason behind it?

When we use Thread Class and When we use Runnable Interface

Please anyone help me.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One technical cause is that Java does not support multiple inheritance. You cannot extend Thread when your class is already extending another. Another situation is when one who maintains the thread and one who provides the functionality are different � something like a generic thread pool.

One more reason is the coding style itself. People say if you "extend" a class you should be "adding" one or more functionalities to it. Such go for Runnable approach if the need is just to implement run() method.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic