java.nio.channels
Interface InterruptibleChannel

All Superinterfaces:
Channel sample code for java.nio.channels.Channel definition code for java.nio.channels.Channel , Closeable sample code for java.io.Closeable definition code for java.io.Closeable
All Known Implementing Classes:
AbstractInterruptibleChannel sample code for java.nio.channels.spi.AbstractInterruptibleChannel definition code for java.nio.channels.spi.AbstractInterruptibleChannel , AbstractSelectableChannel sample code for java.nio.channels.spi.AbstractSelectableChannel definition code for java.nio.channels.spi.AbstractSelectableChannel , DatagramChannel sample code for java.nio.channels.DatagramChannel definition code for java.nio.channels.DatagramChannel , FileChannel sample code for java.nio.channels.FileChannel definition code for java.nio.channels.FileChannel , Pipe.SinkChannel sample code for java.nio.channels.Pipe.SinkChannel definition code for java.nio.channels.Pipe.SinkChannel , Pipe.SourceChannel sample code for java.nio.channels.Pipe.SourceChannel definition code for java.nio.channels.Pipe.SourceChannel , SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel , ServerSocketChannel sample code for java.nio.channels.ServerSocketChannel definition code for java.nio.channels.ServerSocketChannel , SocketChannel sample code for java.nio.channels.SocketChannel definition code for java.nio.channels.SocketChannel

public interface InterruptibleChannel
extends Channel sample code for java.nio.channels.Channel definition code for java.nio.channels.Channel

A channel that can be asynchronously closed and interrupted.

A channel that implements this interface is asynchronously closeable: If a thread is blocked in an I/O operation on an interruptible channel then another thread may invoke the channel's close sample code for java.nio.channels.InterruptibleChannel.close() definition code for java.nio.channels.InterruptibleChannel.close() method. This will cause the blocked thread to receive an AsynchronousCloseException sample code for java.nio.channels.AsynchronousCloseException definition code for java.nio.channels.AsynchronousCloseException .

A channel that implements this interface is also interruptible: If a thread is blocked in an I/O operation on an interruptible channel then another thread may invoke the blocked thread's interrupt sample code for java.lang.Thread.interrupt() definition code for java.lang.Thread.interrupt() method. This will cause the channel to be closed, the blocked thread to receive a ClosedByInterruptException sample code for java.nio.channels.ClosedByInterruptException definition code for java.nio.channels.ClosedByInterruptException , and the blocked thread's interrupt status to be set.

If a thread's interrupt status is already set and it invokes a blocking I/O operation upon a channel then the channel will be closed and the thread will immediately receive a ClosedByInterruptException sample code for java.nio.channels.ClosedByInterruptException definition code for java.nio.channels.ClosedByInterruptException ; its interrupt status will remain set.

A channel supports asynchronous closing and interruption if, and only if, it implements this interface. This can be tested at runtime, if necessary, via the instanceof operator.

Since:
1.4

Method Summary
 void close sample code for java.nio.channels.InterruptibleChannel.close() definition code for java.nio.channels.InterruptibleChannel.close() ()
          Closes this channel.
 
Methods inherited from interface java.nio.channels.Channel sample code for java.nio.channels.Channel definition code for java.nio.channels.Channel
isOpen sample code for java.nio.channels.Channel.isOpen() definition code for java.nio.channels.Channel.isOpen()
 

Method Detail

close sample code for java.nio.channels.InterruptibleChannel.close() definition code for java.nio.channels.InterruptibleChannel.close()

void close()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes this channel.

Any thread currently blocked in an I/O operation upon this channel will receive an AsynchronousCloseException sample code for java.nio.channels.AsynchronousCloseException definition code for java.nio.channels.AsynchronousCloseException .

This method otherwise behaves exactly as specified by the Channel sample code for java.nio.channels.Channel.close() definition code for java.nio.channels.Channel.close() interface.

Specified by:
close sample code for java.nio.channels.Channel.close() definition code for java.nio.channels.Channel.close() in interface Channel sample code for java.nio.channels.Channel definition code for java.nio.channels.Channel
Specified by:
close sample code for java.io.Closeable.close() definition code for java.io.Closeable.close() in interface Closeable sample code for java.io.Closeable definition code for java.io.Closeable
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs