aspose file tools*
The moose likes Threads and Synchronization and the fly likes Theard Class and Runnable interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Theard Class and Runnable interface" Watch "Theard Class and Runnable interface" New topic
Author

Theard Class and Runnable interface

M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 92
Hi All,

I have a doubt regarding Thread class and Runnable interface. We can extend from a Thread class or we can implement the Runnable interface for a class to follow multithreading. It is recommended that we use Runnable interface as my class will be able to extend from any other class in that case. But my doubt is that why do we have an option to extend from Thread class. Is there any scenario where extending from Thread is more preferable.

Thanks,
Mehta
Amit Ghai
Ranch Hand

Joined: Mar 24, 2004
Posts: 35
Extract from Java Doc over Runnable - Runnable provides the means for a class to be active while not subclassing Thread. A class that implements
Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. In most cases, the Runnable interface should be used if you are only planning to override the run()method and no other Thread methods.


Reasonable people adapt themselves to the world. Unreasonable people attempt to adapt the world to themselves. All progress, therefore, depends on unreasonable people.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Some people have called it simply a mistake that Thread has a public, nonfinal run() method of its own. There's no good reason why both mechanisms are allowed. It just confuses people.

Remember (and I've said this a lot lately) that the people who wrote the core Java API classes had no prior experience in writing in Java, and this shows in many of their design choices. Implementation mistakes have been fixed over the years, but the API design problems remain.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Theard Class and Runnable interface
 
Similar Threads
Interface doubt
Doubt in Threads
Thread related
run() method Doubt
Interface doubt from K&B