Path: blob/master/src/java.base/share/classes/java/nio/channels/InterruptibleChannel.java
41159 views
/*1* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*/2728package java.nio.channels;2930import java.io.IOException;313233/**34* A channel that can be asynchronously closed and interrupted.35*36* <p> A channel that implements this interface is <i>asynchronously37* closeable:</i> If a thread is blocked in an I/O operation on an38* interruptible channel then another thread may invoke the channel's {@link39* #close close} method. This will cause the blocked thread to receive an40* {@link AsynchronousCloseException}.41*42* <p> A channel that implements this interface is also <i>interruptible:</i>43* If a thread is blocked in an I/O operation on an interruptible channel then44* another thread may invoke the blocked thread's {@link Thread#interrupt()45* interrupt} method. This will cause the channel to be closed, the blocked46* thread to receive a {@link ClosedByInterruptException}, and the blocked47* thread's interrupt status to be set.48*49* <p> If a thread's interrupt status is already set and it invokes a blocking50* I/O operation upon a channel then the channel will be closed and the thread51* will immediately receive a {@link ClosedByInterruptException}; its interrupt52* status will remain set.53*54* <p> A channel supports asynchronous closing and interruption if, and only55* if, it implements this interface. This can be tested at runtime, if56* necessary, via the {@code instanceof} operator.57*58*59* @author Mark Reinhold60* @author JSR-51 Expert Group61* @since 1.462*/6364public interface InterruptibleChannel65extends Channel66{6768/**69* Closes this channel.70*71* <p> Any thread currently blocked in an I/O operation upon this channel72* will receive an {@link AsynchronousCloseException}.73*74* <p> This method otherwise behaves exactly as specified by the {@link75* Channel#close Channel} interface. </p>76*77* @throws IOException If an I/O error occurs78*/79public void close() throws IOException;8081}828384