File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread class

 
Harveen Batra
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is much more likely to get an answer in the Threads and Synchronization forum, so I've moved it.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic