• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why subclass a Thread

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
There are 2 ways to use thread in java - Subclass Thread or implement Runnable.
Sub classing cannot be done when my class wants
to extend some other class and also Runnable approach allow creation of Singleton pattern.

My question is what is the use of allowing subclassing of Thread, when what is required in both the approaches is write code in run().
Why would anyone subclass a Thread ?? Any points in favour of subclassing a Thread is what I need.
Thanks in advance.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're having the same conversation here
Dave.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You subclass a Thread for the same reason you would subclass any other class. To extend its functionality.
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you sub class a Thread class, for example, it's like saying your class "is a" Thread. This means that you can call the start() method on an instance of the class and do not really need to create an instance of the Thread class because really an instance of your class "is a" thread.
I like extending Thread more than implementing runnable.
Does this help?
[ May 29, 2002: Message edited by: Aaron O'Brien ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic