-
- All Superinterfaces:
- AutoCloseable, Channel, Closeable
- All Known Subinterfaces:
- AsynchronousByteChannel
- All Known Implementing Classes:
- AsynchronousFileChannel, AsynchronousServerSocketChannel, AsynchronousSocketChannel
public interface AsynchronousChannel extends Channel
A channel that supports asynchronous I/O operations. Asynchronous I/O operations will usually take one of two forms:Future
<V> operation(...)void operation(... A attachment,
CompletionHandler
<V,? super A> handler)
CompletionHandler
is used to consume the result of many I/O operations.In the first form, the methods defined by the
Future
interface may be used to check if the operation has completed, wait for its completion, and to retrieve the result. In the second form, aCompletionHandler
is invoked to consume the result of the I/O operation when it completes or fails.A channel that implements this interface is asynchronously closeable: If an I/O operation is outstanding on the channel and the channel's
close
method is invoked, then the I/O operation fails with the exceptionAsynchronousCloseException
.Asynchronous channels are safe for use by multiple concurrent threads. Some channel implementations may support concurrent reading and writing, but may not allow more than one read and one write operation to be outstanding at any given time.
Cancellation
The
Future
interface defines thecancel
method to cancel execution. This causes all threads waiting on the result of the I/O operation to throwCancellationException
. Whether the underlying I/O operation can be cancelled is highly implementation specific and therefore not specified. Where cancellation leaves the channel, or the entity to which it is connected, in an inconsistent state, then the channel is put into an implementation specific error state that prevents further attempts to initiate I/O operations that are similar to the operation that was cancelled. For example, if a read operation is cancelled but the implementation cannot guarantee that bytes have not been read from the channel then it puts the channel into an error state; further attempts to initiate aread
operation cause an unspecified runtime exception to be thrown. Similarly, if a write operation is cancelled but the implementation cannot guarantee that bytes have not been written to the channel then subsequent attempts to initiate awrite
will fail with an unspecified runtime exception.Where the
cancel
method is invoked with themayInterruptIfRunning
parameter set totrue
then the I/O operation may be interrupted by closing the channel. In that case all threads waiting on the result of the I/O operation throwCancellationException
and any other I/O operations outstanding on the channel complete with the exceptionAsynchronousCloseException
.Where the
cancel
method is invoked to cancel read or write operations then it is recommended that all buffers used in the I/O operations be discarded or care taken to ensure that the buffers are not accessed while the channel remains open.- Since:
- 1.7
-
-
Method Detail
-
close
void close() throws IOException
Closes this channel.Any outstanding asynchronous operations upon this channel will complete with the exception
AsynchronousCloseException
. After a channel is closed, further attempts to initiate asynchronous I/O operations complete immediately with causeClosedChannelException
.This method otherwise behaves exactly as specified by the
Channel
interface.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurs
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
25/11/2024 02:15:21 Cette version de la page est en cache (à la date du 25/11/2024 02:15:21) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/nio/channels/AsynchronousChannel.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.