extends Thread vs implements Runnable
Thread
Class T1 extends Thread {
public void run(){...}
}
Run with:
new T1().start();
Runnable
Class R2 implements Runnable{
public void run(){...}
}
Run with:
Thread t2 = new Thread(R2);
t2.start();
R1 still allows you to extend a class (and thus, the behaviour), which is not possible with T1.
Further, multiple threads of T2 shares the same runnable instance, where multiple T1 creating unique instances.
If you don't need extention behaviour, use rather Runnable implementation.
Class T1 extends Thread {
public void run(){...}
}
Run with:
new T1().start();
Runnable
Class R2 implements Runnable{
public void run(){...}
}
Run with:
Thread t2 = new Thread(R2);
t2.start();
R1 still allows you to extend a class (and thus, the behaviour), which is not possible with T1.
Further, multiple threads of T2 shares the same runnable instance, where multiple T1 creating unique instances.
If you don't need extention behaviour, use rather Runnable implementation.