InterruptibleChannel


InterruptibleChannel java.nio.channels

Java 1.4 closeable

Channels that implement this marker interface have two important properties that are relevant to multithreaded programs: they are asynchonously closeable and interruptible . When the close( ) method of an InterruptibleChannel is called, any other thread that is blocked waiting for an I/O operation to complete on that channel will stop blocking and receive an AsynchronousCloseException . Furthermore, if a thread is blocked waiting for an I/O operation to complete on an InterruptibleChannel , then another thread may call the interrupt( ) method of the blocked thread. This causes the interrupt status of the blocked thread to be set and causes the thread to wake up and receive an ClosedByInterruptException (a subclass of AsynchronousCloseException ). As the name of this interrupt implies, the channel that the thread was blocked on is closed as a side-effect of the thread interruption. There is no way to interrupt a blocked thread without closing the channel upon which it is blocked. This ability to interrupt a blocked thread is particularly noteworthy because it has never worked reliably with the older java.io API.

All the concrete channel implementations that are part of this package implement InterruptibleChannel . Note, however, that methods such as Channels.newChannel( ) may return channel objects that are not interruptible. You can use the instanceof to determine whether an unknown channel object implements this interface.

Figure 13-28. java.nio.channels.InterruptibleChannel

 public interface  InterruptibleChannel  extends Channel {  // Public Instance Methods  void  close  ( ) throws java.io.IOException;   } 

Implementations

java.nio.channels.spi.AbstractInterruptibleChannel



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net