You should extend a Thread
as much as you extend other library classes.
Take a List
for example, more specifically ArrayList
, you could add extra behaviour on it, like rejecting a value when adding if a certain predicate fails.
Then you can call that an PredicatedArrayList
.
It is still a debate whether you want to extend ArrayList
here or not, but that debate is not up for this question.
So an example of extending a thread would be a thread that kills itself after a specific amount of time. Then you would have SuicidingThread extends Thread
, which could have a constructor taking the time.
This even fortifies the argument that you should put your actual tasks in a Runnable
.
Like Runnable somethingRunnable = new SomeClass();
, where SomeClass implements Runnable
.
Now you can do either:
Thread someThread = new Thread(somethingRunnable);
Thread someThread = new SuicidingThread(somethingRunnable, 5, TimeUnit.DAYS);
So this would be an usecase for extending thread.