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

Discussion

Consider interrupting a thread blocked in stream I/O. Which statement is correct?

  • A.Interrupting a thread blocked reading from an ordinary InputStream is a compile-time error.
  • B.Interrupting a thread blocked reading from an ordinary InputStream does not unblock it.
  • C.Interrupting a thread blocked reading from an ordinary InputStream throws InterruptedException.
  • D.Interrupting a thread blocked reading from an ordinary InputStream throws IOException immediately.

Answer: B

Only the documented blocking calls, wait, join and sleep, respond to an interrupt by throwing. A thread parked inside a plain stream read simply has its interrupt status set and stays blocked until data arrives or the stream is closed. Closing it from another thread is the usual way to break out.

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

Post your comment

Please log in or register to post a comment.