Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/02/2010, 19:42
Avatar de Xerelo
Xerelo
 
Fecha de Ingreso: mayo-2009
Mensajes: 2.175
Antigüedad: 15 años
Puntos: 306
Respuesta: Threads: ¿Cómo usar wait() y notify()?

[URL="http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html"]http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html[/URL]

Leyendo el tutorial de Sun, dice que al llamar a interrupt() produce una InterruptedException que saca al hilo del estado wait(), y que normalmente (aunque no siempre) continúa con la ejecución del hilo.

He cambiado la clase poniendo a ésta forma

Cita:
class ThirdThread extends Thread {
public void run () {
try {
System.out.println(" Third thread starts running.");
wait();
} catch (Exception e) { }
System.out.println(" Third thread finishes running.");
}
}
He comprobado que al volver ejecutar el interrupt() pasa por el catch, y efectivamente continúa con la ejecución del hilo apareciendo el mensaje deseado, pero todavía no he conseguido que funcione utilizando el notify().

Seguiré investigando, pero se agradece cualquier ayuda o idea.