This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two ways of creating the threads  RSS feed

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
As I was going through threads I just want to know the process of creating the threads is two way either by extending thread class or by implementing runnable interface, My query is that why the java have provided the two ways , I am doing lot of googling for that ,I just wanted to know what's the technical reason behind introduing the two ways..!!
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There just two different approaches both of which have been superseded to some extent. Implementing runnable is usually the preferred choice one reason for which is inheritance i.e. If you have sub classed thread you can't inherit from anything else (multiple inheritance), I guess if you were a beginner you might find the concept of a Thread class more natural and its a wrapper for other methods i.e. it represents a thread rather than a unit of work so it does have its uses.

You should probably me more looking at Executors / Tasks etc in modern java.

 
Tim Moores
Saloon Keeper
Posts: 3511
77
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!