在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这个异常是什么意思,会在什么样的情况下出现?
怪我咯2017-04-17 17:33:44
FILE 및 SOCKET의 BIO 모드는 중단할 수 없으며 AIO/NIO는 중단할 수 있으며 NIO 선택에는 중단을 구현하는 특별한 방법이 있습니다(파이프는 UNIX에서 사용됨/루프백 포트는 Windows에서 사용됨)