Extending Thread versus implementing Runnable
Implementation of Runnable
has the advantage (and in some cases, the only possible option) of allowing the implementation to extend another class. It is particularly helpful when you would like to add thread-like behavior to an existing class. Implementing Runnable
allows more flexibility in usage, but otherwise, there is no difference in functionality compared to the extending of the Thread
class.
The Thread
class has several constructors that allow setting the thread name and the group it belongs to. Grouping of threads helps to manage them in the case of many threads running in parallel. The Thread
class has also several methods that provide information about the thread’s status and its properties and allows us to control its behavior.
As you have seen, the thread’s identifier (ID) is generated automatically. It cannot be changed but can be reused after the thread is terminated. Several threads, on the other hand...