Java theory and practice: Dealing with InterruptedException
Not all blocking methods throw InterruptedException
. The input and output stream classes may block waiting for an I/O to complete, but they do not throw InterruptedException
, and they do not return early if they are interrupted. However, in the case of socket I/O, if a thread closes the socket, blocking I/O operations on that socket in other threads will complete early with a SocketException
. The nonblocking I/O classes in java.nio
also do not support interruptible I/O, but blocking operations can similarly be canceled by closing the channel or requesting a wakeup on the Selector
. Similarly, attempting to acquire an intrinsic lock (enter a synchronized
block) cannot be interrupted, but ReentrantLock
supports an interruptible acquisition mode.
Read full article from Java theory and practice: Dealing with InterruptedException
No comments:
Post a Comment