Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these statements about the interrupt status after InterruptedException is thrown is correct?

  • A.When sleep() throws InterruptedException the thread's interrupt status remains set.
  • B.When sleep() throws InterruptedException the interrupt status is set only if it was clear before.
  • C.sleep() never throws InterruptedException; only wait() does.
  • D.When sleep() throws InterruptedException the thread's interrupt status has already been cleared.

Answer: D

For a thread blocked in wait, join or sleep, interrupt() clears the interrupt status and delivers InterruptedException. So by the time the catch block runs, isInterrupted() reports false. Code that wants to pass the interruption on has to restore it by calling Thread.currentThread().interrupt().

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.