InterruptibleChannel
Stay organized with collections
Save and categorize content based on your preferences.
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.
Public Method Summary
abstract
void
|
close()
Closes this channel.
|
Inherited Method Summary
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
Public Methods
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-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 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eInterruptibleChannel\u003c/code\u003e allows asynchronous closing and interruption of I/O operations.\u003c/p\u003e\n"],["\u003cp\u003eIf a thread is blocked on an \u003ccode\u003eInterruptibleChannel\u003c/code\u003e, closing the channel will throw \u003ccode\u003eAsynchronousCloseException\u003c/code\u003e to the blocked thread.\u003c/p\u003e\n"],["\u003cp\u003eInterrupting a thread blocked on an \u003ccode\u003eInterruptibleChannel\u003c/code\u003e will close the channel and throw a \u003ccode\u003eClosedByInterruptException\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eclose()\u003c/code\u003e method on an \u003ccode\u003eInterruptibleChannel\u003c/code\u003e behaves like the \u003ccode\u003eChannel\u003c/code\u003e interface's \u003ccode\u003eclose()\u003c/code\u003e but throws \u003ccode\u003eAsynchronousCloseException\u003c/code\u003e to blocked threads.\u003c/p\u003e\n"]]],["The `InterruptibleChannel` interface allows for asynchronous closing and interruption of channels. If a thread is blocked in an I/O operation on such a channel, another thread can close it, causing an `AsynchronousCloseException`, or interrupt the blocked thread, resulting in a `ClosedByInterruptException`. This interface also enables checking for these behaviors via the `instanceof` operator. The primary action is the `close()` method, which closes the channel and may throw an `AsynchronousCloseException` to a blocked thread.\n"],null,["public interface **InterruptibleChannel** implements [Channel](../../../../reference/java/nio/channels/Channel.html) \n\n|---|---|---|\n| Known Indirect Subclasses [AbstractInterruptibleChannel](../../../../reference/java/nio/channels/spi/AbstractInterruptibleChannel.html), [AbstractSelectableChannel](../../../../reference/java/nio/channels/spi/AbstractSelectableChannel.html), [DatagramChannel](../../../../reference/java/nio/channels/DatagramChannel.html), [FileChannel](../../../../reference/java/nio/channels/FileChannel.html), [Pipe.SinkChannel](../../../../reference/java/nio/channels/Pipe.SinkChannel.html), [Pipe.SourceChannel](../../../../reference/java/nio/channels/Pipe.SourceChannel.html), [SelectableChannel](../../../../reference/java/nio/channels/SelectableChannel.html), [ServerSocketChannel](../../../../reference/java/nio/channels/ServerSocketChannel.html), [SocketChannel](../../../../reference/java/nio/channels/SocketChannel.html) |---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------| | [AbstractInterruptibleChannel](../../../../reference/java/nio/channels/spi/AbstractInterruptibleChannel.html) | Base implementation class for interruptible channels. | | [AbstractSelectableChannel](../../../../reference/java/nio/channels/spi/AbstractSelectableChannel.html) | Base implementation class for selectable channels. | | [DatagramChannel](../../../../reference/java/nio/channels/DatagramChannel.html) | A selectable channel for datagram-oriented sockets. | | [FileChannel](../../../../reference/java/nio/channels/FileChannel.html) | A channel for reading, writing, mapping, and manipulating a file. | | [Pipe.SinkChannel](../../../../reference/java/nio/channels/Pipe.SinkChannel.html) | A channel representing the writable end of a [Pipe](../../../../reference/java/nio/channels/Pipe.html). | | [Pipe.SourceChannel](../../../../reference/java/nio/channels/Pipe.SourceChannel.html) | A channel representing the readable end of a [Pipe](../../../../reference/java/nio/channels/Pipe.html). | | [SelectableChannel](../../../../reference/java/nio/channels/SelectableChannel.html) | A channel that can be multiplexed via a [Selector](../../../../reference/java/nio/channels/Selector.html). | | [ServerSocketChannel](../../../../reference/java/nio/channels/ServerSocketChannel.html) | A selectable channel for stream-oriented listening sockets. | | [SocketChannel](../../../../reference/java/nio/channels/SocketChannel.html) | 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\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.html#close()) method. This will cause the blocked thread to receive an\n[AsynchronousCloseException](../../../../reference/java/nio/channels/AsynchronousCloseException.html).\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.html#interrupt()) method. This will cause the channel to be closed, the blocked\nthread to receive a [ClosedByInterruptException](../../../../reference/java/nio/channels/ClosedByInterruptException.html), 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.html); 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\nPublic Method Summary\n\n|---------------|-----------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/nio/channels/InterruptibleChannel.html#close())() Closes this channel. |\n\nInherited Method Summary \nFrom interface [java.nio.channels.Channel](../../../../reference/java/nio/channels/Channel.html) \n\n|------------------|----------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/nio/channels/Channel.html#close())() Closes this channel. |\n| abstract boolean | [isOpen](../../../../reference/java/nio/channels/Channel.html#isOpen())() Tells whether or not this channel is open. |\n\nFrom interface [java.io.Closeable](../../../../reference/java/io/Closeable.html) \n\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |\n\nFrom interface [java.lang.AutoCloseable](../../../../reference/java/lang/AutoCloseable.html) \n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |\n\nPublic Methods \n\npublic abstract void\n**close**\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.html).\n\nThis method otherwise behaves exactly as specified by the [Channel](../../../../reference/java/nio/channels/Channel.html#close()) interface.\n\n\u003cbr /\u003e\n\nThrows\n\n| [IOException](../../../../reference/java/io/IOException.html) | If an I/O error occurs |\n|---------------------------------------------------------------|------------------------|"]]