-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiHola.java
More file actions
42 lines (35 loc) · 1.06 KB
/
Copy pathMultiHola.java
File metadata and controls
42 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class TestTh extends Thread {
private String nombre;
private int retardo;
// Constructor para almacenar nuestro nombre
// y el retardo
public TestTh( String s,int d ) {
nombre = s;
retardo = d;
}
// El metodo run() es similar al main(), pero para
// threads. Cuando run() termina el thread muere
public void run() {
// Retasamos la ejecución el tiempo especificado
try {
sleep( retardo );
} catch( InterruptedException e ) {
;
}
// Ahora imprimimos el nombre
System.out.println( "Hola Mundo! "+nombre+" "+retardo );
}
}
public class MultiHola {
public static void main( String args[] ) {
TestTh t1,t2,t3;
// Creamos los threads
t1 = new TestTh( "Thread 1",(int)(Math.random()*2000) );
t2 = new TestTh( "Thread 2",(int)(Math.random()*2000) );
t3 = new TestTh( "Thread 3",(int)(Math.random()*2000) );
// Arrancamos los threads
t1.start();
t2.start();
t3.start();
}
}