Maison  >  Questions et réponses  >  le corps du texte

Java当中IO阻塞时调用interrupt的疑问

在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_leeringa_lee2719 Il y a quelques jours390

répondre à tous(1)je répondrai

  • 怪我咯

    怪我咯2017-04-17 17:33:44

    FILE,SOCKET的BIO模式是不可被中断的,AIO/NIO可被中断掉,而且NIO的select实现中断的方式比较特殊(UNIX下用pipe/windows下用环回口)

    répondre
    0
  • Annulerrépondre