0

There is a simple situation like:

Thread A: try to read from a FileChannel like

    length = tun.read(tunPacket.buffer);

This operation is block the this A thread.

Thread B: wait for a user input, (Stop button). When this event happens, calls A's interrupt() method. Despite the fact that FileChannel is implements AbstractInterruptibleChannel, this is not throw ClosedByInterruptException

I'm using Android 6.0, if matter, and there is the documentation

I'm trying to resolve this problem but looks impossible...

Kara
  • 6,115
  • 16
  • 50
  • 57
SPYFF
  • 133
  • 1
  • 6
  • 1
    Hmmm, from the doc, using a common sens, I think that you should rather call `close` on `FileChannel`(in Thread B) not `interrupt()` the thread A ... – Selvin Oct 23 '15 at 15:00
  • Interesting, I tried this, but there is no any `AsynchronousCloseException` or any exception. – SPYFF Oct 23 '15 at 15:12
  • 1
    yeah ... but what tun.read(..) returns then? isn't it -1? ... so you will know in the Thread A that something interrupt reading ... *but there is no any AsynchronousCloseException or any exception* from the doc it meant to be happend(no exception) – Selvin Oct 23 '15 at 15:18
  • Sadly `length` never less than 0, I log it right after read. Looks like read() is not return anything after I close. – SPYFF Oct 23 '15 at 15:42
  • 1
    hmm it should throw: https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/FileChannelImpl.java#294 + https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/channels/spi/AbstractInterruptibleChannel.java#109 – Selvin Oct 23 '15 at 15:51
  • Definitely seems like these ones must throw. Thank you for the help, I'm trying to figure out whats going on. – SPYFF Oct 23 '15 at 17:40

1 Answers1

0
  length = tun.read(tunPacket.buffer);

This operation is block the this A thread.

Clearly not. It wouldn't take long to execute, and your interrupt() could easily have missed it. You haven't presented any evidence that you were actually in that method at the moment interrupt() executed.

user207421
  • 305,947
  • 44
  • 307
  • 483