import java.util.concurrent.TimeUnit; public class HelloRunnable implements Runnable { public void run() { System.out.println("Ejecutando hilo"); System.out.println(Thread.currentThread().getName()); } public static void main(String args[]) { System.out.println(Thread.currentThread().getName()); int i=0; while(i<100) { (new Thread(new HelloRunnable())).start(); try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } i++; } } }
Crear un hilo implementando el interfaz Runnable (Procesos, Java, Hilos)
Except where otherwise noted, Jesusninoc by Jesús N. is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.