Possible Duplicate:
Implementing Runnable vs. extending Thread
I am very much confused about the perfect answer in simple language for above question. In which scenario which is better and why. can anyone explain.
Possible Duplicate:
Implementing Runnable vs. extending Thread
I am very much confused about the perfect answer in simple language for above question. In which scenario which is better and why. can anyone explain.
The Executor classes talk in terms of Runnable
, and for that reason alone I favour implementing the Runnable
interface. You don't carry the baggage of having your code implicitly tied into a thread and frameworks can handle Runnables
in whatever way they prefer.
Use these simple rules:
1) If the main purpose of a class is to be a thread, then subclass Thread
2) If the main purpose of a class is not to be a thread (e.g.: a GUI component), implement Runnable
3) Use Runnable when the thread class is already sub-classed by another class