Peter said:
For a thread blocking on InputStream.read() can I interrupt it
successfully and resume reading after handling the interruption, or
would it be better to use NIO socket channels and avoid blocking
altogether using asynchronous IO?
InputStream.read() blocks until it reads something, detects end of
stream, or receives an exception. Unless you can manage to cause the
read to receive an I/O exception you cannot interrupt it without
forcefully stopping the thread in which it runs (not recommended). I
wouldn't count on being able to resume reading after such a stoppage anyway.
If you anticipate being in a position to interrupt the read in the first
place then you have a multithreaded design in mind. Why not just
perform the needed action in a different thread than the one blocked on
the read? Non-blocking I/O through NIO is another alternative; which
(if either) is better depends on your application.
John Bollinger
(e-mail address removed)