This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Performance  RSS feed

 
Chetan Raju
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Most of us know that a Thread can be instantiated in two ways.

1. by implementing Runnable interface and
2. by extending the Thread class

I need to know what exactly is the difference other than the difference that everyone knows like extending thread will prevent one from extending other classes if required etc... More emphasis at the performances of both methods.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference in performance, and no other major differences than what you already know.

It's not as complicated as you might think.

Look at the API documentation of class Thread. You will see that it implements Runnable.

If you write your own program that uses threads, you can either (1) implement Runnable yourself or (2) extend Thread, which implements Runnable, and override the run() method in your subclass. Either way, the result is the same - you have a Runnable that you can start in a thread.

If you are really curious about how it is implemented behind the scenes, lookup the file src.zip in your JDK installation directory, find the source code for class Thread in there and study it.
[ September 27, 2006: Message edited by: Jesper Young ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to threads forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!