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

Discussion

Restoring the interrupt status after catching InterruptedException - which of the following is true?

  • A.Catching InterruptedException leaves the interrupt status set.
  • B.Restoring the interrupt status requires the thread to be blocked again first.
  • C.A thread's interrupt status can be restored after catching InterruptedException.
  • D.Once InterruptedException has been caught, the interrupt status can no longer be set.

Answer: C

Throwing InterruptedException clears the status, so a method that cannot handle the interruption itself should call Thread.currentThread().interrupt() before returning. That preserves the request for code further up the stack, which would otherwise never learn the thread had been interrupted. Swallowing the exception silently is the mistake it avoids.

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

Post your comment

Please log in or register to post a comment.