FileChannel.read()无法抛出ClosedByInterruptException

时间:2015-10-23 14:53:42

标签: java android filechannel

有一个简单的情况:

主题A :尝试从FileChannel中读取

    length = tun.read(tunPacket.buffer);

此操作阻止此A线程。

主题B :等待用户输入,(停止按钮)。发生此事件时,请调用A的interrupt()方法。尽管FileChannel是实现AbstractInterruptibleChannel,但这不是抛出ClosedByInterruptException

我正在使用Android 6.0,如果问题,并且有the documentation

我正试图解决这个问题,但看起来不可能......

1 个答案:

答案 0 :(得分:0)

  length = tun.read(tunPacket.buffer);
  

此操作阻止此A线程。

显然不是。执行起来不会花费很长时间,而interrupt()可能很容易错过它。您还没有提供任何证据证明您在执行interrupt()时实际上是在该方法中。