I am trying to use Channels.newChannel for an InputStream wrapper to support interrupts. I saw conflicting information about whether this would work. Including comment in ReadableByteChannelImpl: // Not really interruptible
In ReadableByteChannelImpl before making a blocking call to InputStream.read , AbstractInterruptibleChannel.begin is called, which sets up a new Interruptible with sun.misc.SharedSecrets.getJavaLangAccess().blockedOn , which will close the completed InputStream.
protected final void begin() { if (interruptor == null) { interruptor = new Interruptible() { public void interrupt(Thread target) { synchronized (closeLock) { if (!open) return; open = false; interrupted = target; try { AbstractInterruptibleChannel.this.implCloseChannel(); } catch (IOException x) { } } }}; } blockedOn(interruptor); Thread me = Thread.currentThread(); if (me.isInterrupted()) interruptor.interrupt(me); }
Is it true that if an InputStream throws an IOException from a blocked read request, if it is closed by another thread, then ReadableByteChannelImpl will make the interrupted stream intermittent?
source share