Unterbrochene Ausnahme vs isInterrupted in einer while-Schleife

Angenommen, ich habe den folgenden Code:

while(!Thread.currentThread().isInterrupted()){  
    //do something   
    Thread.sleep(5000);  
}

JetztThread.sleep wirft `InterruptedException so sollte es sein:

while(!Thread.currentThread().isInterrupted()){  
   //do something   
   try{  
     Thread.sleep(5000);    
   } catch(InterruptedException e){  

   }
}

Wenn ich das treffecatch wird diewhile Schleife fortsetzen oder muss ich tunThread.currentThread().interrupt()? Wenn ich diese Methode aufrufe, führt das nicht auch zu einerInterruptedException? Ansonsten, wie habe ich die Ausnahme überhaupt bekommen?

Auch wenn ich habe:

while (!Thread.currentThread().isInterrupted()){  
   //do something   
   callMethod();  
}  

private void callMethod(){  
   //do something  
   try {  
     Thread.sleep(5000);    
   } catch(InterruptedException e){  

   }
}

wieder wird meinwhile Schleifenbruch?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage