ak said:
Extending Thread gives you possibility to make simple things quckly.
Implementing Runnable gives you many possibilities:
For example you could have some kind worker thread which all time
fetches next Runnable from some queue and then calls Runnble.run().
So you can make many jobs without creating many threads.
The real question, though, is this: does extending Thread really make
anything simpler? For someone who knows the language, it's just as easy
to write
new Thread(new Runnable() {
public void run()
{
...
}
}).start();
, and the added flexibility will be very much appreciated. On the other
hand, for someone struggling with the language, the code
new Thread() {
public void run()
{
...
}
}.start();
is more mystical, because implementation inheritance from Thread is an
extra level of complexity that doesn't need to be dealt with. Not only
that, but it's a particularly poor example of the use of implementation
inheritance at that!
So the only real reasons I can see to extend Thread are:
1. Some older books taught it that way before it became widely
understood that implementing Runnable is better, so it's the only thing
some people know, and
2. I guess you save a few keystrokes.
In the end, it was clearly a mistake. It doesn't do any terrible amount
of harm, but it really never should have happened.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation