This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Why subclass a  Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why subclass a  Thread" Watch "Why subclass a  Thread" New topic
Author

Why subclass a Thread

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

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.


Groovy
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

We're having the same conversation here
Dave.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

You subclass a Thread for the same reason you would subclass any other class. To extend its functionality.
Aaron O'Brien
Ranch Hand

Joined: May 24, 2002
Posts: 89
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 ]

Aaron O'Brien
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why subclass a Thread
 
Similar Threads
subclassing Thread vs. implementing Runnable
SUBCLASSING THE THREAD CLASS
SUBCLASSING THE THREAD CLASS
when to use runnable?
when extend a class