Está en la página 1de 1

package hilos; import java.util.logging.Level; import java.util.logging.

Logger; public class NewClass extends Thread { private int tiempoDormido; public NewClass(String str) { super(str); this.tiempoDormido=(int)(Math.random()*5000); } public void run() { System.out.println( getName()); System.out.println("Tiempo inactivo "+tiempoDormido); try { Thread.sleep(tiempoDormido); } catch (InterruptedException ex) { Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, e x); } System.out.println("\nTermino mi tiempo de ejecucion en el hilo"); } public static void main (String [] args) { new NewClass("\nHola mundo").start(); new NewClass("\nAndres Benavides").start(); //System.out.println(Math.random()*5000); } }

También podría gustarte