“implements Runnable” vs “extends Thread” in Jav
De quanto tempo passei com threads em Java, encontrei essas duas maneiras de escrever threads:
Withimplements Runnable
:
public class MyRunnable implements Runnable {
public void run() {
//Code
}
}
//Started with a "new Thread(new MyRunnable()).start()" call
Ou comextends Thread
:
public class MyThread extends Thread {
public MyThread() {
super("MyThread");
}
public void run() {
//Code
}
}
//Started with a "new MyThread().start()" call
Existe alguma diferença significativa nesses dois blocos de códig