Excepción interrumpida vs isInterrupted en un bucle while
Supongamos que tengo el siguiente código:
while(!Thread.currentThread().isInterrupted()){
//do something
Thread.sleep(5000);
}
AhoraThread.sleep
lanza `InterruptedException por lo que debería ser así:
while(!Thread.currentThread().isInterrupted()){
//do something
try{
Thread.sleep(5000);
} catch(InterruptedException e){
}
}
Si golpeo elcatch
será elwhile
continuar bucle o tengo que hacerThread.currentThread().interrupt()
? Si llamo a este método, ¿no causará eso también unInterruptedException
? De lo contrario, ¿cómo obtuve la excepción en primer lugar?
También si tengo:
while (!Thread.currentThread().isInterrupted()){
//do something
callMethod();
}
private void callMethod(){
//do something
try {
Thread.sleep(5000);
} catch(InterruptedException e){
}
}
de nuevo será miwhile
ruptura de bucle?