I'm trying to find out what are the possible advantages of extending the Thread class would be?
This is a part of another question which I describe: There is two way of creating threads in Java
- extending from Thread class
- implementing the runnable interface
As expalined here there are several benefits of using runnable interface. My question is what is the advantage of extending from Thread class? The only advantage that comes to my mind is that one can extend from Thread class, and let's say call it ThreadExtended class. Then he/she can add more functionality in ThreadExtended(which I don't know what that might be), and then when he/she wants to create a thread, instead of extending from Thread class, it extends from ThreadExtended.
Is there any advantages in using Thread class instead of Runnable interface? Do you know any class(es) that extends from Thread class and then ask users to extends from those classes if they want to have multithreading capabilities?
public class ThreadExtended extends Thread{
//override some functions || add more functionality to Thread class
}
public class MyThread extends ThreadExtended{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("Using ThreadExtended instead of Thread directly");
}
}
public static void main(String args[])
{
MyThread myThread = new MyThread();
myThread.start();
}
}