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

Thread class

Harveen Batra

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

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 ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Michael Ernest
High Plains Drifter

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:

    The Complete Java 2 Certification Study Guide

    [This message has been edited by Michael Ernest (edited November 15, 2000).]

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: Thread class
It's not a secret anymore!