In several Java projects, I've seen these two ways to create Threads:
With implements Runnable
:
public class MyRunnable implements Runnable {
public void run() {
//Código
}
}
//Iniciada com uma chamada "new Thread(new MyRunnable()).start()"
Or, with extends Thread
:
public class MyThread extends Thread {
public MyThread() {
super("MyThread");
}
public void run() {
//Código
}
}
//Iniciada com uma chamada "new MyThread().start()"
- What is the correct way?
- Is there any advantage or limitation?