在java当中打断一个线程一般是使用一个变量标记和调用interrupt方法
Threads blocked in one of Object's wait() methods or one of Thread's join() or sleep() methods will be woken up, their interrupt status will be cleared, and they receive an InterruptedException.
Threads blocked in an I/O operation of an InterruptibleChannel will have their interrupt status set and receive an ClosedByInterruptException. Also, the channel will be closed.
Threads blocked in a Selector will have their interrupt status set and return immediately. They don't receive an exception in this case.
根据文档里和网上找到的资料看,在io阻塞时调用interrupt其实是无效的
按照我的理解是在while循环里做标记判断,最后final里关闭流
问题1 :
但是有人说在io阻塞时interrupt会抛出io异常?问什么我实验输入输出流的时候,没有出现呢?
问题2 :
还有就是InterruptedIOException这个异常是什么意思,会在什么样的情况下出现?
FILE と SOCKET の BIO モードは中断できません。AIO/NIO は中断できます。NIO 選択には特別な中断実装方法があります (UNIX ではパイプが使用され、Windows ではループバック ポートが使用されます)