Ejemplo de Programa con Hilos en Java
Este ejemplo de codigo muestra como crear, iniciar y detener hilos
public class HilosJava {
public static void main(String args[]) {
GreetingRunnable runnable =
new GreetingRunnable("Hola");
GreetingRunnable runnable2 =
new GreetingRunnable("Mundo");
Thread thread = new Thread(runnable);
Thread thread2 = new Thread(runnable2);
thread.start();
thread2.start();
}
}
class GreetingRunnable implements Runnable {
String name;
public GreetingRunnable(String name) {
this.name = name;
}
public void run() {
while(true) {
System.out.println(name);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
Ejemplos De Hilos En Java Codigo Fuente