Professional Documents
Culture Documents
Curso de Java: Threads: Interface Runnable
Curso de Java: Threads: Interface Runnable
68
Threads:
interface
Runnable
public class MinhaThread extends Thread {
try {
for (int i=0; i<6; i++){
System.out.println(nome + " tem contador valor " + i);
Thread.sleep(valorAdormecida);
}
} catch (InterruptedException e) {
System.out.println(nome + " foi interrompida");
}
t1.start();
t2.start();
}
public MinhaThreadRunnable(String nome, int valorAdormecida){
this.nome = nome;
this.valorAdormecida = valorAdormecida;
new Thread(this).start(); Ou podemos fazer isso diretamente do construtor
}
Qual abordagem é melhor?