I am new to thread. I would like to know which one is better extending from Thread class or Implement Runnable interface in term of performance and why
Joined: Dec 29, 2004
I'm not sure it would really make a difference. Probably would have to code both up and run a profiler to be sure. From a design standpoint it is generally more acceptable to implement Runnable as you are not creating new types of Thread's, but rather building business logic that you want to run in a seperate Thread.
Joined: Aug 07, 2003
The only performance difference is that implementing Runnable with a separate class results in an extra class instantiation and a single method call. Both are trivial compared to anything that method might be doing and should cause no concern.
Design-wise, extend Thread only when you need to override the behavior of the Thread. If you just want a Thread to run some code, implement Runnable and pass it to a Thread. This gives you more options, for example using a thread pool and rerunning your Runnable multiple times.