Stay organized with collections
Save and categorize content based on your preferences.
InterruptibleChannel
public
interface
InterruptibleChannel
implements
Channel
java.nio.channels.InterruptibleChannel
|
Known indirect subclasses
|
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
method. This will cause the blocked thread to receive an
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
method. This will cause the channel to be closed, the blocked
thread to receive a 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
; 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.
Summary
Public methods |
abstract
void
|
close()
Closes this channel.
|
Inherited methods |
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
|
|
Public methods
close
public abstract void close ()
Closes this channel.
Any thread currently blocked in an I/O operation upon this channel
will receive an AsynchronousCloseException
.
This method otherwise behaves exactly as specified by the Channel
interface.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# InterruptibleChannel\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nInterruptibleChannel\n====================\n\n\n`\npublic\n\n\ninterface\nInterruptibleChannel\n`\n\n\n`\n\n\nimplements\n\n`[Channel](/reference/java/nio/channels/Channel)`\n\n\n`\n\n|----------------------------------------|\n| java.nio.channels.InterruptibleChannel |\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [AbstractInterruptibleChannel](/reference/java/nio/channels/spi/AbstractInterruptibleChannel), [AbstractSelectableChannel](/reference/java/nio/channels/spi/AbstractSelectableChannel), [DatagramChannel](/reference/java/nio/channels/DatagramChannel), [FileChannel](/reference/java/nio/channels/FileChannel), [Pipe.SinkChannel](/reference/java/nio/channels/Pipe.SinkChannel), [Pipe.SourceChannel](/reference/java/nio/channels/Pipe.SourceChannel), [SelectableChannel](/reference/java/nio/channels/SelectableChannel), [ServerSocketChannel](/reference/java/nio/channels/ServerSocketChannel), [SocketChannel](/reference/java/nio/channels/SocketChannel) |-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | [AbstractInterruptibleChannel](/reference/java/nio/channels/spi/AbstractInterruptibleChannel) | Base implementation class for interruptible channels. | | [AbstractSelectableChannel](/reference/java/nio/channels/spi/AbstractSelectableChannel) | Base implementation class for selectable channels. | | [DatagramChannel](/reference/java/nio/channels/DatagramChannel) | A selectable channel for datagram-oriented sockets. | | [FileChannel](/reference/java/nio/channels/FileChannel) | A channel for reading, writing, mapping, and manipulating a file. | | [Pipe.SinkChannel](/reference/java/nio/channels/Pipe.SinkChannel) | A channel representing the writable end of a [Pipe](/reference/java/nio/channels/Pipe). | | [Pipe.SourceChannel](/reference/java/nio/channels/Pipe.SourceChannel) | A channel representing the readable end of a [Pipe](/reference/java/nio/channels/Pipe). | | [SelectableChannel](/reference/java/nio/channels/SelectableChannel) | A channel that can be multiplexed via a [Selector](/reference/java/nio/channels/Selector). | | [ServerSocketChannel](/reference/java/nio/channels/ServerSocketChannel) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](/reference/java/nio/channels/SocketChannel) | A selectable channel for stream-oriented connecting sockets. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA channel that can be asynchronously closed and interrupted.\n\nA channel that implements this interface is *asynchronously\ncloseable:* If a thread is blocked in an I/O operation on an\ninterruptible channel then another thread may invoke the channel's [close](/reference/java/nio/channels/InterruptibleChannel#close()) method. This will cause the blocked thread to receive an\n[AsynchronousCloseException](/reference/java/nio/channels/AsynchronousCloseException).\n\nA channel that implements this interface is also *interruptible:*\nIf a thread is blocked in an I/O operation on an interruptible channel then\nanother thread may invoke the blocked thread's [interrupt](/reference/java/lang/Thread#interrupt()) method. This will cause the channel to be closed, the blocked\nthread to receive a [ClosedByInterruptException](/reference/java/nio/channels/ClosedByInterruptException), and the blocked\nthread's interrupt status to be set.\n\nIf a thread's interrupt status is already set and it invokes a blocking\nI/O operation upon a channel then the channel will be closed and the thread\nwill immediately receive a [ClosedByInterruptException](/reference/java/nio/channels/ClosedByInterruptException); its interrupt\nstatus will remain set.\n\nA channel supports asynchronous closing and interruption if, and only\nif, it implements this interface. This can be tested at runtime, if\nnecessary, via the `instanceof` operator.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[close](/reference/java/nio/channels/InterruptibleChannel#close())`() ` Closes this channel. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` `[java.nio.channels.Channel](/reference/java/nio/channels/Channel)` ` |---------------------|------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](/reference/java/nio/channels/Channel#close())`() ` Closes this channel. | | ` abstract boolean` | ` `[isOpen](/reference/java/nio/channels/Channel#isOpen())`() ` Tells whether or not this channel is open. | ||\n| From interface ` `[java.io.Closeable](/reference/java/io/Closeable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||\n| From interface ` `[java.lang.AutoCloseable](/reference/java/lang/AutoCloseable)` ` |------------------|---------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||\n\nPublic methods\n--------------\n\n### close\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void close ()\n```\n\nCloses this channel.\n\nAny thread currently blocked in an I/O operation upon this channel\nwill receive an [AsynchronousCloseException](/reference/java/nio/channels/AsynchronousCloseException).\n\nThis method otherwise behaves exactly as specified by the [Channel](/reference/java/nio/channels/Channel#close()) interface.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Throws ||\n|-----------------------------------------------|------------------------|\n| [IOException](/reference/java/io/IOException) | If an I/O error occurs |"]]