Java当中IO阻塞时调用interrupt的疑问
ringa_lee
ringa_lee 2017-04-17 17:31:44
0
1
385

在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这个异常是什么意思,会在什么样的情况下出现?

ringa_lee
ringa_lee

ringa_lee

全部回覆(1)
刘奇

FILE,SOCKET的BIO模式是不可被中斷的,AIO/NIO可被中斷掉,而且NIO的select實現中斷的方式比較特殊(UNIX下用pipe/windows下用環回口)

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!