Originally posted by badri nath:
Hi Arvind
Ya i know that implementing is best practice as you rightly said if we extend thread class then we will not be able to extend any other class. But if there is approach then it might be suitable in some applications.As of now im not able to know in what type of situations it is required.
Please, can any one make this clear by showing an example.
With Regards Badri
There is no scenario that mandates extending Thread rather than implementing Runnable that I am aware of. However, I have created a ThreadWorker that maintained a BlockingQueue of Runnables and ran them as they were made available via an execute(Runnable) method. Since there was an "is a" relationship there and I considered the ThreadWorker a Thread I made it inherit. That way I could set the priority of a ThreadWorker, for example, or make a ThreadWorker that was a daemon Thread, etc. So I would say that if you want your class to be a Thread, rather than simply run in one, inherit it, but that's a very rare scenario and could be similary accomplished with a Runnable implementation.