File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread class" Watch "Thread class" New topic
Author

Thread class

Harveen Batra
Greenhorn

Joined: Nov 14, 2000
Posts: 5
want to know the exact difference between extending the Thread class and implementing the Runnable interface?
pros and cons regarding the two?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This is much more likely to get an answer in the Threads and Synchronization forum, so I've moved it.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

In extending the Thread class, you'd inherit Thread behavior and (I assume) override the run() method. This has the advantage of combining the runnable code (Thread implements Runnable) with the methods that put it in motion in the VM. If you want to extend Thread's behavior in some way, this approach is the right one.
Implementing Runnable lets you decouple Thread's registration/scheduling/monitoring apparatus from the execution stack; not only that, you can inherit from something else. Implementing Runnable is more flexible than extending Thread, so I'd consider it the default of the two choices.
------------------
Michael Ernest, co-author of:


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread class