public class Main {
public static void main (String args[]){
TH t1= new TH(1);
TH t2= new TH(2);
TH t3= new TH(3);
t1.start();
t2.start();
t3.start();
}
}
-----------------------------------------------------------------------------------------------------------
public class TH extends Thread{
private int n;
public void run(){
try{
Thread.sleep((long)(Math.random()*5)*1000);
}catch(Exception e ){}
System.out.println("Termino: "+n);
}
public TH(int n){
this.n = n;
}
}
Salida por consola:
Termino: 1
Termino: 2
Termino: 3
-----------
Termino: 2
Termino: 1
Termino: 3
-----------
Termino: 1
Termino: 3
Termino: 2
No hay comentarios:
Publicar un comentario