1

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.

Community
  • 1
  • 1
aj983
  • 293
  • 2
  • 5
  • 12

2 Answers2

2

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.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

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

hovanessyan
  • 30,580
  • 6
  • 55
  • 83