File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why subclass a  Thread" Watch "Why subclass a  Thread" New topic

Why subclass a Thread

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

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

Joined: Mar 06, 2001
Posts: 13459

We're having the same conversation here
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:
subject: Why subclass a Thread
jQuery in Action, 3rd edition