Ejecutando el método run().
Ver “ejecutor”.
A continuación, hay 2 threads operando: el original y el recién arrancado. El siguiente método arranca 3 threads y sigue, así que tenemos 4 threads concurrentes:
public static void
main(String[] args) { for (int i = 0; i < 3; i++) { String id = String.valueOf((char) ('A' + i)); int count = (int) (Math.random() * 10); Thread thread = ...; thread.start(); } System.out.println("Repeaters ..."); } |
Cuando se ejecuta este código, vemos algo así:
> java Repeaters |
A: 2 B: 3 C: 2 Repeaters ... A: 1 B: 2 C: 1 A: end B: 1 C: end B: end |
Temas relacionados