El método Java join() de thread me confunde un poco. He ejemplo siguienteComprender el método join() ejemplo
class MyThread extends Thread {
private String name;
private int sleepTime;
private Thread waitsFor;
MyThread(String name, int stime, Thread wa) { … }
public void run() {
System.out.print("["+name+" ");
try { Thread.sleep(sleepTime); }
catch(InterruptedException ie) { }
System.out.print(name+"? ");
if (!(waitsFor == null))
try { waitsFor.join(); }
catch(InterruptedException ie) { }
System.out.print(name+"] ");
Y
public class JoinTest2 {
public static void main (String [] args) {
Thread t1 = new MyThread("1",1000,null);
Thread t2 = new MyThread("2",4000,t1);
Thread t3 = new MyThread("3",600,t2);
Thread t4 = new MyThread("4",500,t3);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
¿En qué orden se terminan los hilos?
¿Es esta una pregunta capciosa? ¿O tarea? :) – bzlm
acaba de leer un libro electrónico y encontré ese ejemplo, en realidad el hilo de ejecución espera el hilo donde se llama a las uniones para terminar, tal vez debería salir hoy: D –
Espera a que el hilo muera. http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html#join() –