Explain different ways of creating a thread. Which one would you prefer and why ?
There are three ways that can be used in order for a
Thread to be created:
- A class may extend the
- A class may implement the
- An application can use the
Executorframework, in order to create a thread pool.
Runnable interface is preferred, as it does not require an object to inherit the
Thread class. In case your application design requires multiple inheritance, only interfaces can help you. Also, the thread pool is very efficient and can be implemented and used very easily.