Stay organized with collections
Save and categorize content based on your preferences.
InterruptibleChannel
interface InterruptibleChannel : Channel
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 Unit |
Closes this channel.
|
Public methods
close
abstract fun close(): Unit
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 java.nio.channels.Channel#close interface.
Exceptions |
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
If an I/O error occurs |
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# InterruptibleChannel\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nInterruptibleChannel\n====================\n\n```\ninterface InterruptibleChannel : Channel\n```\n\n|---------------------------------------------|\n| [java.nio.channels.InterruptibleChannel](#) |\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [AbstractInterruptibleChannel](/reference/kotlin/java/nio/channels/spi/AbstractInterruptibleChannel) |------------------------------------------------------------------------------------------------------|-------------------------------------------------------| | [AbstractInterruptibleChannel](/reference/kotlin/java/nio/channels/spi/AbstractInterruptibleChannel) | Base implementation class for interruptible channels. | |\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Indirect Subclasses [AbstractSelectableChannel](/reference/kotlin/java/nio/channels/spi/AbstractSelectableChannel), [DatagramChannel](/reference/kotlin/java/nio/channels/DatagramChannel), [FileChannel](/reference/kotlin/java/nio/channels/FileChannel), [Pipe.SinkChannel](/reference/kotlin/java/nio/channels/Pipe.SinkChannel), [Pipe.SourceChannel](/reference/kotlin/java/nio/channels/Pipe.SourceChannel), [SelectableChannel](/reference/kotlin/java/nio/channels/SelectableChannel), [ServerSocketChannel](/reference/kotlin/java/nio/channels/ServerSocketChannel), [SocketChannel](/reference/kotlin/java/nio/channels/SocketChannel) |------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | [AbstractSelectableChannel](/reference/kotlin/java/nio/channels/spi/AbstractSelectableChannel) | Base implementation class for selectable channels. | | [DatagramChannel](/reference/kotlin/java/nio/channels/DatagramChannel) | A selectable channel for datagram-oriented sockets. | | [FileChannel](/reference/kotlin/java/nio/channels/FileChannel) | A channel for reading, writing, mapping, and manipulating a file. | | [Pipe.SinkChannel](/reference/kotlin/java/nio/channels/Pipe.SinkChannel) | A channel representing the writable end of a [Pipe](/reference/kotlin/java/nio/channels/Pipe). | | [Pipe.SourceChannel](/reference/kotlin/java/nio/channels/Pipe.SourceChannel) | A channel representing the readable end of a [Pipe](/reference/kotlin/java/nio/channels/Pipe). | | [SelectableChannel](/reference/kotlin/java/nio/channels/SelectableChannel) | A channel that can be multiplexed via a [Selector](/reference/kotlin/java/nio/channels/Selector). | | [ServerSocketChannel](/reference/kotlin/java/nio/channels/ServerSocketChannel) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](/reference/kotlin/java/nio/channels/SocketChannel) | A selectable channel for stream-oriented connecting sockets. | |\n\nA channel that can be asynchronously closed and interrupted.\n\nA 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](/reference/kotlin/java/nio/channels/AsynchronousCloseException).\n\nA 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](../../lang/Thread.html#interrupt()) method. This will cause the channel to be closed, the blocked thread to receive a [ClosedByInterruptException](/reference/kotlin/java/nio/channels/ClosedByInterruptException), and the blocked thread's interrupt status to be set.\n\nIf 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](/reference/kotlin/java/nio/channels/ClosedByInterruptException); its interrupt status will remain set.\n\nA 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.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [close](#close())`()` Closes this channel. |\n\n| Inherited functions ||\n|---|---|\n| From class [Channel](/reference/kotlin/java/nio/channels/Channel) |------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------| | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isOpen](/reference/kotlin/java/nio/channels/Channel#isOpen())`()` Tells whether or not this channel is open. \u003cbr /\u003e | ||\n\nPublic methods\n--------------\n\n### close\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun close(): Unit\n```\n\nCloses this channel.\n\nAny thread currently blocked in an I/O operation upon this channel will receive an [AsynchronousCloseException](/reference/kotlin/java/nio/channels/AsynchronousCloseException).\n\nThis method otherwise behaves exactly as specified by the java.nio.channels.Channel#close interface.\n\n| Exceptions ||\n|-----------------------|-----------------------------------|\n| `java.lang.Exception` | if this resource cannot be closed |\n| `java.io.IOException` | If an I/O error occurs |"]]