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

Discussion

Which one of the following statements about Thread.interrupted() compared with isInterrupted() is true?

  • A.Thread.interrupted() clears the interrupt status, while isInterrupted() leaves it unaffected.
  • B.isInterrupted() clears the interrupt status, while Thread.interrupted() leaves it unaffected.
  • C.Both methods clear the interrupt status; only their return type differs.
  • D.Neither method changes the interrupt status; only catching InterruptedException clears it.

Answer: A

The static Thread.interrupted() tests and clears the status of the current thread, so two consecutive calls can return true then false. The instance method isInterrupted() reports another thread's status and explicitly leaves it unaffected. Confusing the two produces a flag that seems to vanish.

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

Post your comment

Please log in or register to post a comment.